Dependency Injection In Spring Framework
Guys, its very important concept in spring read it carefully
In this IOC, consider when our class object need to get any primitive values or it need to access any other class objects or it may need any collection type to access then, some external person will provide the required things (primitive values or objects or collections) to our class object.
Actually In IOC, our class is not responsible to get all these collaborating (required things like primitive values, collections bla bla) values explicitly, I mean it doesn’t perform any lookup operations for the things to access.
Come to Spring framework, hear one external person who will provide [Injects] all the required things to our spring bean class is the spring ioc container
Types of dependency injections
For injecting the required things to the current spring class (spring bean) , spring ioc container will do this in different ways…
- Setter injection
- Construction injection
- Interface injection
But in spring we have only setter, constructor injections but not interface injection, In spring 2.x we have interface injection
In this type of injection, the spring container uses setter method in the dependent (our) class for injecting its dependencies (primitive values..Or any).
Spring container knows whether to perform setter or constructor injection by reading the information from an external file called spring configuration file
In case of setter injection, the class must contain a setter method to get dependencies other wise spring container doesn’t inject the dependencies to dependent object
In spring we call each class as spring bean, this bean is no way related with the java bean
Spring bean and java bean both are not same because a java bean needs definitely a public default constructor but in spring bean, some time we include default constructor or sometimes we do not.
First Consider Our spring bean having the dependency in the form of primitive values, I mean our class need some primitive values…
And let us see an example on setter injection with primitive values in the next session[ before that check how to install spring framework ]