Pages

Showing posts with label Spring. Show all posts
Showing posts with label Spring. Show all posts

Tuesday, 8 April 2014

Difference between Construct and Setter Injection



Constructor Injection 

Setter Injection 

1. Injecting bean properties through argumented constructor.

1.Injecting bean properties through setter method.
2. It will first inject the bean dependencies then create the instance of current bean.

2. It will first create the bean instance and then inject the bean dependencies.

3. Chance of forming Cyclic Dependency

3. No chance of Cyclic Dependency.


4. In case of Auto-wiring it can done with "construtor autowiring process ".

4. It can be possible with two autowiring concept ,
    a. byName                b. byType

5. No chance of getting UnsatisfiedDependencyExeption.

5. UnsatisfiedDependencyException in case of byType autowiring. 

6. In case of Explicit Wiring,
<constructor-arg/> tag is use to define this injection. 
6. <property/> tag s used to define this injection

7. In Cyclic Dependency , only one bean will be injecting by ignoring cyclic dependency. 
7. Doesn't form Cyclic Dependency, so both the bean will be injected successfully.

Saturday, 5 April 2014

Difference between Explicit and Auto Wiring in the Spring




Explicit Wiring 

Auto Wiring

1. Explicit Wiring means hard-coding the dependencies in the XML.

1. Not hard-coding in the XML file rather Container to detect and inject Dependencies.
2. Mainly it can be done in two ways
    a. Constructor   b. Setter injection 
2. It can be done in four ways 
a. byName     b. byType
c. constructor  d. autodetect
3. It requires writing more content in the XML which ultimately makes XML little complex.  
3. It doesn't require much writing rather need just any of the four value to the autowire attribute. 

Wednesday, 30 October 2013

Difference between BeanFactory and ApplicationContext container

BeanFactory : 
  • BeanFactory is an interface which has one concrete cubclass called XmlBeanFactory.
    Following is the way to create BeanFactory container instance
    BeanFactory bf=new XmlBeanFactory(res);
    Resources may be of type ClasspathResource or FileSystemResources.
  • BeanFactory will be loaded lazily by default.
  • BeanFactory container does not support annotation.
  • BeanFactory does not support BeanPostProcessor.
  • BeanFactory does not support Event publishing.
  • BeanFactory does not provide a way to resolve message bundle.
ApplicationContext : 
  • ApplicationContext is an interface which has 3 concrete subclass called
    ClasspathXmlApplicationContext
    FileSystemXmlApplicationContext
    XmlWebApplicationContext
  • BeanFactory configured with ApplicationContext container will be loaded aggressively by default.
  • ApplicationContext container do support annotation.
  • ApplicationContext container do support BeanPostProcessor.
  • Application context do provide a way to resolve message bundle.