Tags

links:
http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/beans.html

summary:
– @Autowired eliminates the need of cons and setter
– use constructors to set required properties
– use setters for optional or those with default values

– “constructor-arg” in bean tag ~= new() with parameter(s)
– “property” in bean tag ~= setter with value(s)
– id and class alone in bean tag ~= new() with no-arg

– example,

 <bean id="service" class="example.ServiceImpl">
    <constructor-arg ref="required"/>
    <property name="optional" ref="optional"/>
 </bean>

 <bean id="required" class="example.RequiredImpl" />
 <bean id="optional" class="example.OptionalImpl" />

same in code as,

 RequiredImpl required = new RequiredImpl();
 OptionalImpl optional = new OptionalImpl();
 ServiceImpl service = new ServiceImpl(required);
 service.setOptional(optional);
Advertisements