Pages

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.

1 comment: