Dependency Injection in Spring framework
Before understanding Dependency Injection(DI) in Spring framework, I recommend you to understand Dependency Injection design pattern As explained in above link, Dependency Injection is a design pattern in which object's properties are set by external entity. External entity can be simple java class which configure object's properties. Spring core (IoC) container acts as external entity to configure object's properties. There are 2 ways in Spring framework to achieve DI. 1. Setter Injection 2. Constructor Injection Let's write simple example to understand DI in Spring framework. We will set primitive values in Employee class using setter injection. I have used maven to add Spring framework related jars. You can add these external jars in eclipse by right click on project --> Build Path --> Configure Build Path... --> Add external JARs --> select jar --> Ok. Project Structure: POM.xml: <project xmlns:xsi="http://www.w3.org/...
Comments
Post a Comment