Showing posts with label spring. Show all posts
Showing posts with label spring. Show all posts

Wednesday, March 27, 2013

Spring Framework - MethodReplacer Example in spring


Spring framework with AOP show many magic.One of them is Method Replacer .In this activity the called method is replaced by another method. To understand clearly have a good example-
Directory Structure-

Tuesday, March 26, 2013

Spring Framework - Example of Database Connectivity with DataSource


After lot of basic tutorials and topics now we start database connectivity .In spring framework DataSource in used to define the database configuration.In XML configuration file use DriverManagerDataSource class is used to set the database configuration like driver,pool,username and password.so understand clearly here below is a simple example-
Directory Structure-
                                                           

Monday, March 25, 2013

Spring Framework- Execption handling in AOP


Hureeeee!!!!!  Today in spring framework we learn some intresting with AOP, so today topic is Execption handling. AOP contain a method proceed() . If this method is proceed with exception then it pass the controll of the program to the catch block, In That type examples we can also used @AfterThrowing , @AfterReturning ,@Around . here we use @Around annotation to follow the AOP. So here below is the example --


Spring Framework - Example to use @Before annotation with args() in AOP


Here In AOP, we discuss that how use @Before(args()).Here args() is contain the name of arguments with pass to the function and also can use that argument.Now see a example to understand that-

Monday, March 18, 2013

Spring Framework-Example to use JoinPoint in AOP


Hello Friends, After discussing the pointcuts in last post Now discuss on Joinpoint . A Joinpoint is a point in the execution of the application where an aspect can be plugged in. this point could be a method being called Here is a example to understands the use of pointcuts-

Sunday, March 17, 2013

Spring Framework- Example to Use Pointcuts in AOP


In Aspect Oriented Programming (AOP) Advice define the what and when we call . The Pointcuts define where.A pointcut definition matches one or more jointpoints .Here discuss a simple example to use pointcut -

Directory Structure-


Saturday, March 16, 2013

Spring Framework- Simple Aspect Oriented Programming Example


                     Aspect Oriented Programming basically provide alternative way to achive the inheritance and the delegation.In AOP define the comman fuctionality in one place,but you can define where and how this functionlity is applied.  The basic example of the aspect oriented programming is describe here-

Directory Structure-

Monday, June 25, 2012

Spring Framework Tutorials


Lets learn spring framework with fun. Here provide step by step tutorials to learn spring framework,with simple  and easily understandable example .
visit to see contain of spring framework  -http://www.technicaltoday.com/p/spring.html

Sunday, June 24, 2012

BeanNameAware and ApplicationContextAware in spring


Spring offer awareness with beans and Applicationcontext.
BeanNameAware interface provide to know  bean information like name aware(know who you are).
ApplicationContextAware interface provide to know context information like context aware(Know where you live).
public setBeanName(String bean);
        this method contain the name of the bean which is implement the interface BeanNameAware
public void setApplicationContext(ApplicationContext context)
        this contain the container of context information where that bean exist.necessary to implement that class with ApplicationContextAware interface.
 let illustrate example-

Bean postprocessing in spring


Spring provide two opportunities or us to cut into a bean's lifecycle and review or alter its configuration. this is called 'post processing'.The BeanPostProcessor interface gives two opportunities to alter a bean after it has been    
created or wired.
public interface BeanPostProcessor
{
   Object postProcessBeforeInitialization (Object bean,String name) throw BeanException;
   Object postProcessAfterInitialization (Object bean,String name) throw BeanException;
}
                    The postProcessBeforeInitialization() method called before the bean initialization.likewise postProcessAfterInitialization () method called immediately after initialization.

Let see a example to understand -
Directory Structure-

Monday, June 18, 2012

Create beans with factory method (singleton class) in spring


Mostly the beans that are configure in the spring application context will be created by calling one of the class's constructor.
In the case of configuring singleton class(class that only create one instance) or bean  allowing throw factory method.
Here illustrate a example to understand it-
Directory Structure-

Sunday, June 17, 2012

Spring Framework- Event Handling


Spring Framework also provide an another feature to promote loose coupling ,which is Application Event handling. Using Events, an Event publisher object can communicate with other objects without even  knowing which object is listen.and event listener can work to event without knowing which object publish the events. Publisher Object that object ,who publish the event or call the event and Listener always listen the events that are occurs.
                                          To make a custom event extends the class with ApplicationEvent class.The ApplicationEventPublisher has contain publishEvent() method that enable to publish ApplicationEvents (Custom Events).Any ApplicationListener that is registered with the onApplicationEvent() method in application,listen the events.
To understand The Event handling Lets illustrate a simple example-
Directory Structure-

Saturday, June 16, 2012

What is difference between id and name of bean?


id of bean is a unique in container  for each bean . id is basically used to access the bean anywhere. but it not accept the url matching like in spring framework. name is partially work like id but it can accept url matching.
example-
<bean name="/*.html" class="com.test.handler">
In web application when url contain this pattern it call that class. The id is not preferred for that feature. It caught a exception at the run time.

Friday, June 15, 2012

How to import xml file in another xml ?


We can split our container definition in many xml file and can use it  in diffrent manner.One of them,load all xml in ApplicationContext or BeanFactory. Another is import all xml file in a perticular xml file now load this single xml in context.
Here we discuss that how to import a xml file into another xml file.for this use <import > tag in <beans> tag and set the path of xml in resource  property of import tag. To illustrate it lets see a example-
Directory Structure-

Wednesday, June 13, 2012

How to Injecting the bean properties before load xml in application and out side xml


in Spring Framework we injected the beans in xml file ,than the xml loads in application.But here  another new feature of spring framework is that we can inject the bean property outside the xml and before the load xml in application. applyBeanPropertyValues() method on AutowireCapableBeanFactory to apply a bean definition’s properties to an existing bean.(click for example)

Spring Framework- Injecting the bean property before load xml in application and out side xml("applyBeanPropertyValues()")


Normally we injected the beans in xml file ,than the xml loads in application.But here  another new feature of spring framework is that we can inject the bean property outside the xml and before the load xml in application.
To more understand it let illustrate below example-
Directory structure of project-

Spring Framework- inner bean example


Spring framework  contain different types of bean properties injctions provided.one of them is inner bean injection.this is look like java inner classes,classes that are defined with in the scope of other class is known as inner class. similarly inner beans are beans that are defined with in the scope of another bean. To illustrate this let see a example-
Directory structure of project -

Spring Framework- Bean Injections and Types


Java bean properties are private and each will have a pair of methods in form of set and get prefix.set methods are set the bean property so these called setter methods and get methods use to get the property(value) are called getter method. this concept is known as bean injections

Bean properties are injection many different ways as the requirements-.
1. Injecting simple values.
2.Injecting through constructor
3. Referencing other bean.
4.Injecting inner bean.
Lets Understand all these with an example-

Sunday, June 3, 2012

Spring Framework- Bean Scope


Spring provide the facility to define the scope of bean ,to set limit instances or define area of bean. To define the bean scope set the scope properties with different parameters-

1.singleton-Allow the bean to a single instance per container.
2.prototype-Allow bean to be instantiate any number of times.
3.request-Allow a bean definition to an HTTP request.
4.session-Allow a bean definition to an HTTP session.
5.global-session-Allow a bean definition to a global HTTP session,used in only context.

Example of set the property scope-
   <bean id="scope" class="com.test.BeanScopeProgram" scope="singleton"></bean>

Spring Framework- Autowiring with "autodetect"


When we set the autowire property by "autodetect" than it autowired by constructor first then using by Type and byName. if any exception occurs handle the same way as with constructor and byType wiring.
Let see example-
Directory structure-



 

Site Status

Man Behind Technical Today

Hello, I am Navin Bansal. I am a student of MCA in Rajsthan Institute of Engineering and Technology and owner of this blog. I share my view and ideas among people.