1 Reply Latest reply on Mar 13, 2010 10:49 AM by jaikiran

    Resources injection in JBoss 5

    morettoni

      Hi list, I'm new to Jboss, I'm moving one app from Glassfish to JBoss,  but I got a little issue. Into a stateless session bean I have this:

       

      ...

      @Resource(name = "theConfig")

      private Properties configProperties;

      ...

       

      and the AS injects the properties defined by the admin-console into the app.

      Now, this is possible with JBoss?

      I found one solution using properties-service.xml, but the properties are visible by the  System.getProperties and I need to modify the app.

      Another solution talks about creating a file with this:

      <?xml version="1.0" encoding="UTF-8"?>
      <jndi:binding name="theConfig">

        <java:properties xmlns:java="urn:jboss:java-properties" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
          <java:property>
            <java:key>remote.address</java:key>
            <java:value>192.168.0.7</java:value>
          </java:property>
          <java:property>
            <java:key>dumpinfo</java:key>
            <java:value>1</java:value>
          </java:property>
        </java:properties>
      </jndi:binding>

      ... but exploring the jndi tree I can't find any "theConfig" resource name! There are any solutions to this? Thanks!!

       

      --

      Luca

        • 1. Re: Resources injection in JBoss 5
          jaikiran

          Luca, welcome to the forums

           

          Nice thing you are trying out there!

           

          morettoni wrote:

           


          Another solution talks about creating a file with this:

          <?xml version="1.0" encoding="UTF-8"?>
          <jndi:binding name="theConfig">

            <java:properties xmlns:java="urn:jboss:java-properties" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
              <java:property>
                <java:key>remote.address</java:key>
                <java:value>192.168.0.7</java:value>
              </java:property>
              <java:property>
                <java:key>dumpinfo</java:key>
                <java:value>1</java:value>
              </java:property>
            </java:properties>
          </jndi:binding>

          ... but exploring the jndi tree I can't find any "theConfig" resource name! There are any solutions to this? Thanks!


           

          1) That file isn't complete. What you need is this:

           

           

          <?xml version="1.0" encoding="UTF-8"?>
           <mbean code="org.jboss.naming.JNDIBindingServiceMgr"     
                  name="jboss.apps:name=myapp">    
               <attribute name="BindingsConfig" serialDataType="jbxb">    
                   <jndi:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"     
                                  xmlns:jndi="urn:jboss:jndi-binding-service:1.0"    
                                  xs:schemaLocation="urn:jboss:jndi-binding-service resource:jndi-binding-service_1_0.xsd">     
                      <jndi:binding name="theConfig">
          
                          <java:properties xmlns:java="urn:jboss:java-properties" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
                              <java:property>
                                  <java:key>remote.address</java:key>
                                  <java:value>192.168.0.7</java:value>
                              </java:property>
                              <java:property>
                                  <java:key>dumpinfo</java:key>
                                  <java:value>1</java:value>
                              </java:property>
                          </java:properties>
                      </jndi:binding>
          
                  </jndi:bindings>    
               </attribute>    
          </mbean>    
          
          

           

          2) Name this file to end with -service.xml (ex: myapp-service.xml) and place it in JBOSS_HOME/server/< servername>/deploy folder and start the server. You should be able to find "theConfig" jndi binding available under the Global namespace in JNDIView through jmx-console.

           

          3) Finally to inject this, you will have to use the mappedName of the @Resource annotation. Like this:

           

          @Resource(mappedName = "theConfig")
          private Properties configProperties;