12 Replies Latest reply on Mar 13, 2006 9:50 AM by chung chung

    Porting application from SpringFramework to JBoss

    Boris Kozel Newbie

      I'm going to port my existing spring-based application to JBoss.
      (not standalone)

      Certainly I'll use Microcontainer (MC)
      It looks great.
      Yet I couldn't find some features I need.

      The question is whether the following features are available in MC?

      1. PropertyResolver
      How one can set some properties in external file and then reference them
      in jboss-bean.xml . Like this : ${my.property}

      2. Multiple jboss-bean.xml.
      Is it possible to have a few config files? How to name them and where to place?

      3. Event framework.

      The example of using emitters/receivers of kernel events, mentioned in docs, is needed. (I've not found any in docs/examples)

      Particularily:
      a) How to register listener( whether MC may do it automatically on discoveriong some well-known interface?)

      b) How to send event from bean ?

      To be continued...

        • 1. Re: Porting application from SpringFramework to JBoss
          Adrian Brock Master

           

          "borisk" wrote:

          1. PropertyResolver
          How one can set some properties in external file and then reference them
          in jboss-bean.xml . Like this : ${my.property}


          What does property resolver do?

          You should certainly be able to reference system properties in the xml, j
          ust like you can do now for MBeans. Though I haven't tried it.

          That comes from JBossXB
          SchemaBinding
           private boolean replacePropertyRefs = true;
          


          The only thing loads system properties in JBoss is;

          e.g.
          <bean name="SystemProperties code="org.jboss.varia.property.SystemPropertiesService"/>
           // Use a list of urls
           <property name="uRLlist">resource:/some/path</property>
           // Set properties inline
           <property name="properties>
           com.acme.blah=true
           </property>
          </bean>
          
          resource: is a special JBoss protocol that does:
          Thread.currentThread().getContextClassLoader().getResource();
          
          This class isn't included in the standalone mc distribution.


          • 2. Re: Porting application from SpringFramework to JBoss
            Adrian Brock Master

             

            "borisk" wrote:

            2. Multiple jboss-bean.xml.
            Is it possible to have a few config files? How to name them and where to place?

            3. Event framework.

            The example of using emitters/receivers of kernel events, mentioned in docs, is needed. (I've not found any in docs/examples)

            Particularily:
            a) How to register listener( whether MC may do it automatically on discoveriong some well-known interface?)

            b) How to send event from bean ?

            To be continued...


            http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossHelp
            One thread one question please :-)

            • 3. Re: Porting application from SpringFramework to JBoss
              Boris Kozel Newbie

              Thanks for prompt response to my 1st question.
              I see I should post only one question in thread.
              So I'll split them..

              • 4. Re: Porting application from SpringFramework to JBoss
                Boris Kozel Newbie

                adrian@jboss.org wrote:

                What does property resolver do?

                You should certainly be able to reference system properties in the xml, j
                ust like you can do now for MBeans. Though I haven't tried it.


                org.jboss.varia.property.SystemPropertiesService is very useful service for
                setting System properties and then retrieving them in code.

                What I mean is the ability to configure bean in jboss-bean.xml
                and istead of hard-coded values inject a reference to this value.

                File : my.properties:
                my.property=foo


                jboss-bean.xml: (is smth like this possible?)

                <bean name="myBean" code="com.Foo"/>
                 <property name="bar>
                 ${my.property}
                 </property>
                </bean>
                


                • 5. Re: Porting application from SpringFramework to JBoss
                  Adrian Brock Master

                  Yes, but how does it know to use my.properties to get my.property?

                  • 6. Re: Porting application from SpringFramework to JBoss
                    Boris Kozel Newbie

                     

                    "adrian@jboss.org" wrote:
                    Yes, but how does it know to use my.properties to get my.property?



                    In springframework it is implemented as follows:

                    1. use factorybean:

                    <bean class = "PropertyPlaceholderConfigurer">
                     <property name="location"><value>my.properties</value></property>
                    </bean>


                    2. Container register this bean and then uses it for substituting all ${..}
                    according to my.properties data when instantiating other beans at proper time during lifecycle.

                    This feature enables you not to touch xml file, when you need to change config values. Very convenient


                    • 7. Re: Porting application from SpringFramework to JBoss
                      Adrian Brock Master

                      Ok. So does Spring have a java.util.Properties per xml file?

                      You still don't explain what makes the "PropertyPlaceholderConfigurer" special?

                      Perhaps we need:

                      <deployment properties="my.properties">
                      
                      <bean>
                       <property name="blah">${my.property}</property>
                      </bean>
                      
                      </deployment>
                      


                      Where it first looks in the local "my.properties" then System.getProperties()?

                      In general, I don't like this kind of property stuff, I prefer the use "metadata"
                      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=73653

                      • 8. Re: Porting application from SpringFramework to JBoss
                        chung chung Newbie

                         

                        "borisk" wrote:


                        2. Multiple jboss-bean.xml.
                        Is it possible to have a few config files? How to name them and where to place?



                        Like Apache Jakarta hivemind...

                        The descriptor is named hivemodule.xml and is stored in the META-INF directory of the module ,to provide a runtime and compile-time description of each HiveMind module.
                        The root element of the descriptor is the element.
                        The <sub-module> element is used to identify an additional HiveMind module deployment descriptor.
                        This is used when a single JAR file contains logically distinct packages, each of which should be treated as an individual HiveMind module. This can also be useful as a way to reduce developer conflict against a single, large, central module descriptor by effectively breaking it into smaller pieces. Sub-modules identified in this way must still have their own unique module id.


                        <'module>
                        ....
                        <sub-module descriptor=a relative path... />
                        </'module>


                        • 9. Re: Porting application from SpringFramework to JBoss
                          chung chung Newbie

                           

                          "bkeh12" wrote:
                          "borisk" wrote:


                          2. Multiple jboss-bean.xml.
                          Is it possible to have a few config files? How to name them and where to place?



                          Like Apache Jakarta hivemind...

                          The descriptor is named hivemodule.xml and is stored in the META-INF directory of the module ,to provide a runtime and compile-time description of each HiveMind module.
                          The root element of the descriptor is the <module> element.
                          The <sub-module> element is used to identify an additional HiveMind module deployment descriptor.
                          This is used when a single JAR file contains logically distinct packages, each of which should be treated as an individual HiveMind module. This can also be useful as a way to reduce developer conflict against a single, large, central module descriptor by effectively breaking it into smaller pieces. Sub-modules identified in this way must still have their own unique module id.


                          <'module>
                          ....
                          <sub-module descriptor=a relative path... />
                          </'module>


                          Is Microcontainer possible to have ?

                          • 12. Re: Porting application from SpringFramework to JBoss
                            chung chung Newbie

                            Can try to reduce XML to simplify ?

                            
                            <deployment xmlns="urn:jboss:bean-deployer:2.0">
                            
                             <bean name="Test" class="org.jboss.example.microcontainer.constructor.ConstructorBeanImpl" >
                             <annotation name="org.jboss.aop.microcontainer.prototype.introductions.jmx.JMX">
                             <attribute name="name" value="test:name='mytest'"/>
                             <attribute name="exposedInterface" value="org.jboss.example.microcontainer.constructor.ConstructorBeanInf"/>
                             </annotation>
                             <constructor>
                             <parameter class="int">4</parameter>
                             </constructor>
                             
                             <demand state="Described">mbeanserver</demand>
                             <demand state="Described">repository</demand>
                             <demand state="Described">jmxintroduction</demand>
                             <demand state="Described">jmxbinding</demand>
                            
                             </bean>
                            
                             <bean name="MBeanServer" class="java.lang.Object">
                             <constructor factoryClass="javax.management.MBeanServerFactory" factoryMethod="createMBeanServer"/>
                             <supply>mbeanserver</supply>
                             </bean>
                            
                             <bean name="Repository" class="org.jboss.aop.microcontainer.prototype.AOPKernelRepository" >
                             <constructor factoryClass="org.jboss.aop.microcontainer.prototype.AOPKernelRepository" factoryMethod="instance"/>
                             <supply>repository</supply>
                             </bean>
                            
                             <bean name="AspectManager" class="org.jboss.aop.AspectManager">
                             <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
                             </bean>
                            
                             <beanfactory name="JMXAdvice" class="org.jboss.aop.microcontainer.prototype.introductions.jmx.JMXIntroduction"/>
                            
                             <bean name="JMXAspect" class="org.jboss.aop.microcontainer.prototype.Aspect">
                             <property name="advice"><inject bean="JMXAdvice"/></property>
                             <property name="manager"><inject bean="AspectManager"/></property>
                             </bean>
                            
                             <bean name="JMXIntroduction" class="org.jboss.aop.microcontainer.prototype.IntroductionBinding">
                             <property name="classes">@org.jboss.aop.microcontainer.prototype.introductions.jmx.JMX</property>
                             <property name="interfaces">
                             <list elementClass="java.lang.String">
                             <value>org.jboss.kernel.spi.dependency.KernelControllerContextAware</value>
                             </list>
                             </property>
                             <property name="manager"><inject bean="AspectManager"/></property>
                             <supply>jmxintroduction</supply>
                             </bean>
                            
                             <bean name="JMXBinding" class="org.jboss.aop.microcontainer.prototype.AspectBinding">
                             <property name="pointcut">execution(* $instanceof{org.jboss.kernel.spi.dependency.KernelControllerContextAware}->$implements{org.jboss.kernel.spi.dependency.KernelControllerContextAware}(..))</property>
                             <property name="aspect"><inject bean="JMXAspect" property="definition"/></property>
                             <property name="manager"><inject bean="AspectManager"/></property>
                             <supply>jmxbinding</supply>
                             </bean>
                            
                            </deployment>
                            


                            normal is as below
                            
                            <deployment xmlns="urn:jboss:bean-deployer:2.0">
                            
                             <bean name="MBeanServer" class="java.lang.Object">
                             <constructor factoryClass="javax.management.MBeanServerFactory" factoryMethod="createMBeanServer"/>
                             </bean>
                            
                             <bean name="Repository" class="org.jboss.aop.microcontainer.prototype.AOPKernelRepository">
                             <constructor factoryClass="org.jboss.aop.microcontainer.prototype.AOPKernelRepository" factoryMethod="instance"/>
                             </bean>
                            
                             <bean name="AspectManager" class="org.jboss.aop.AspectManager">
                             <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
                             </bean>
                            
                             <beanfactory name="JMXAdvice" class="org.jboss.aop.microcontainer.prototype.introductions.jmx.JMXIntroduction"/>
                            
                             <bean name="JMXAspect" class="org.jboss.aop.microcontainer.prototype.Aspect">
                             <property name="advice"><inject bean="JMXAdvice"/></property>
                             <property name="manager"><inject bean="AspectManager"/></property>
                             </bean>
                            
                             <bean name="JMXIntroduction" class="org.jboss.aop.microcontainer.prototype.IntroductionBinding">
                             <property name="classes">@org.jboss.aop.microcontainer.prototype.introductions.jmx.JMX</property>
                             <property name="interfaces">
                             <list elementClass="java.lang.String">
                             <value>org.jboss.kernel.spi.dependency.KernelControllerContextAware</value>
                             </list>
                             </property>
                             <property name="manager"><inject bean="AspectManager"/></property>
                             </bean>
                            
                             <bean name="JMXBinding" class="org.jboss.aop.microcontainer.prototype.AspectBinding">
                             <property name="pointcut">execution(* $instanceof{org.jboss.kernel.spi.dependency.KernelControllerContextAware}->$implements{org.jboss.kernel.spi.dependency.KernelControllerContextAware}(..))</property>
                             <property name="aspect"><inject bean="JMXAspect" property="definition"/></property>
                             <property name="manager"><inject bean="AspectManager"/></property>
                             </bean>
                             <bean name="Test" class="org.jboss.example.microcontainer.constructor.ConstructorBeanImpl" >
                             <annotation name="org.jboss.aop.microcontainer.prototype.introductions.jmx.JMX">
                             <attribute name="name" value="test:name='mytest'"/>
                             <attribute name="exposedInterface" value="org.jboss.example.microcontainer.constructor.ConstructorBeanInf"/>
                             </annotation>
                             <constructor>
                             <parameter class="int">4</parameter>
                             </constructor>
                             </bean>