Loading
Spring Dependency Injection

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  How many ways you could achieve Dependency Injection in Spring ?


Ans)

Dependency Injection could be accomplished in two ways either with constructor arguments
or with Setter Getter methods.

Setter-based dependency injection is realized by calling setters on your beans after invoking
a no-argument constructor or no-argument static factory method to instantiate your bean. Beans
defined in the BeanFactory that use setter-based dependency injection are true JavaBeans.

<bean id="exampleBean" class="examples.ExampleBean">
  <property name="beanOne"><ref bean="anotherExampleBean"/></property>
</bean>

Constructor-based dependency injection is realized by invoking a constructor with a number of
arguments, each representing a collaborator or property.

<bean id="exampleBean" class="examples.ExampleBean">
  <constructor-arg><ref bean="anotherExampleBean"/></constructor-arg>
</bean>



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Spring Dependency Injection


Spring Dependency Injection

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free