Spring integration

Spring integration allows Spring XML files to be used for IoC without Spring BeanFactory/ApplicationContext. This is possible as JBoss Microcontainer supports the same set of IoC features as Spring. All you need to do is declare the right namespace: urn:jboss:spring-beans:2.0. See the following example for a simple plain Spring XML example.

      <beans xmlns="urn:jboss:spring-beans:2.0">

         <bean id="testBean" class="org.jboss.test.spring.support.SimpleBean">
            <constructor-arg index="2">
               <value>SpringBean</value>
            </constructor-arg>
            <constructor-arg index="0">
               <value>1</value>
            </constructor-arg>
            <constructor-arg index="1">
               <value>3.14159</value>
            </constructor-arg>
            <property name="mylist">
               <list value-type="java.lang.String">
                  <value>onel</value>
                  <value>twol</value>
                  <value>threel</value>
               </list>
            </property>
            <property name="myset">
               <set value-type="java.lang.String">
                  <value>ones</value>
                  <value>twos</value>
                  <value>ones</value>
               </set>
            </property>
            <property name="mymap">
               <map key-type="java.lang.String">
                  <entry>
                     <key>
                        <value>test_key</value>
                     </key>
                     <value type="java.lang.String">myvalue</value>
                  </entry>
               </map>
            </property>
         </bean>

      </beans>
   

But things would be too easy if we just let get away with plain Spring XML. So what you can do is mix and match Microcontainer beans with Spring beans. It doesn't matter which starting element you choose, as long as your beans have the right namespace. Let see this on the next two examples.

      <deployment xmlns="urn:jboss:bean-deployer:2.0">

         <bean name="oldBean" class="org.jboss.test.spring.support.OldBean">
            <property name="testBean">
               <inject/>
            </property>
         </bean>

         <bean xmlns="urn:jboss:spring-beans:2.0" id="testBean" class="org.jboss.test.spring.support.SimpleBean">
            <property name="mylist">
               <list value-type="java.lang.String">
                  <value>onel</value>
                  <value>twol</value>
                  <value>threel</value>
               </list>
            </property>
         </bean>

      </deployment>
   

In this example we have a Microcontainer beans at the start (deployment element at the start), and we mix them with Spring beans.

      <beans xmlns="urn:jboss:spring-beans:2.0">

         <bean id="testBean" class="org.jboss.test.spring.support.SimpleBean">
            <property name="refBean">
               <ref bean="oldBean"/>
            </property>
         </bean>

         <bean xmlns="urn:jboss:bean-deployer:2.0" name="oldBean" class="org.jboss.test.spring.support.OldBean">
            <property name="javaBeanString">JavaBean</property>
         </bean>

      </beans>
   

Here we start with Spring XML and add Microcontainer beans.

As you can see, all you need to change from your existing XML, be it Spring or Microcontainer, is the namespace on the staring Spring beans element or bean element.