http://www.mkyong.com/spring/spring-auto-wiring-beans-in-xml/
Showing posts with label Spring. Show all posts
Showing posts with label Spring. Show all posts
Wednesday, August 7, 2013
Monday, July 29, 2013
Spring Inversion of Control
Bean Creation
- code POJO, add bean configuration element to the Spring XML configuration file or annotate the POJO
Inversion of Control
1. Constructor Injection
2. Setter Injection
3. Reference Injection
source: http://www.springbyexample.org/examples/intro-to-ioc.html
- code POJO, add bean configuration element to the Spring XML configuration file or annotate the POJO
<bean id="message" class="org.springbyexample.di.xml.BelleMessage"/>
Inversion of Control
1. Constructor Injection
public ConstructorMessage(String message) { this.message = message; }
<bean id="message" class="org.springbyexample.di.xml.ConstructorMessage"> <constructor-arg value="Spring is fun." /> </bean>
2. Setter Injection
public void setMessage(String message) { this.message = message; }
<bean id="message" class="org.springbyexample.di.xml.SetterMessage"> <property name="message" value="Spring is fun." /> </bean>
3. Reference Injection
<bean id="message" class="org.springbyexample.di.xml.SetterMessage"> <property name="message" ref="springMessage"" /> </bean>
source: http://www.springbyexample.org/examples/intro-to-ioc.html
Subscribe to:
Posts (Atom)