Thursday, June 20, 2013

Spring Tutorial Part 2 - Object creation, constructor-args, property injection


<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.1.xsd">        
  <context:annotation-config/>
  <context:component-scan base-package="springapp.beans"/>
 
  <!-- BEAN-1 -->
  <bean id="address1" class="springapp.beans.Address">
      <property name="city" value="Chicago"/>
      <property name="state" value="Illinois"/>
  </bean>
   
  <!--BEAN-2 CONSTRUCTOR_ARG name, type, ref Example-->
  <bean name="house2" class="springapp.beans.House" >
    <constructor-arg name="owner" value="CONS_ARG_name_type_ref" />      
    <constructor-arg type="double" value="122334.56" />
    <constructor-arg ref="address1"/>
  </bean>

    <!--BEAN-3 CONSTRUCTOR_ARG index, inner-bean Example-->
  <bean name="house3" class="springapp.beans.House" >
    <constructor-arg index="0" value="CONS_ARG_index-innerbean" />      
    <constructor-arg index="1" value="32322.45" />
    <constructor-arg>
        <bean class="springapp.beans.Address">
            <property name="city" value="Houston"/>
            <property name="state" value="Texas"/>
        </bean>
    </constructor-arg>
  </bean>
 
 <!--BEAN-4 PROPERTY Injection Example-->
   <bean name="house4" class="springapp.beans.House" >
    <constructor-arg index="0" value="PROP_INJ_HOUSE" />      
    <property name="price" value="82356.22" />
    <property name="features">
      <list value-type="java.lang.String">
       <value>Dishwasher</value>
       <value>Garage</value>
       <value>Patio</value>
     </list>
    </property>
    <property name="address" ref="address1"/>
  </bean>
 
 </beans>

No comments:

Post a Comment