5 Replies Latest reply on Oct 2, 2009 12:49 PM by jprio

    @Resource and systemproperties-service.xml

    jprio

      Hi all,
      I have a SLSB with a @Resource annotation :

      import org.jboss.ejb3.annotation.Depends;

      @Stateless(name = "SimpleSLSBResource", mappedName = "SimpleEJB30SLSBResource")
      @Remote({com.jp.ejb3.ISimpleSLSB.class})
      @Depends({"jboss:type=Service,name=SystemProperties"})
      public class SimpleSLSBResource implements ISimpleSLSB {

      @Resource(name = "serverName")
      String = "testserver";

      and i also have a ejb-jar.xml to define the resource :


      <ejb-name>SimpleSLSBResource</ejb-name>
      <env-entry>
      <env-entry-name>serverName</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>${serverName}</env-entry-value>
      </env-entry>


      and finally a systemProperties-service.xml to set the value of the resource :


      serverName=production



      When i start my JBoss AND THEN deploy my EJB, "serverName" is resolved to "production" => OK
      When i start my JBoss with my EJB in the deploy directory, "serverName" is not resolved (= ${serverName}) => KO

      I'm working on JBoss 5.1.0GA, jdk6.

      Have I made a mistake with the @Depends tag ?

        • 1. Re: @Resource and systemproperties-service.xml
          jaikiran

           

          <env-entry-value>${serverName}</env-entry-value>


          Try

          <env-entry-value>${jboss.server.name}</env-entry-value>


          • 2. Re: @Resource and systemproperties-service.xml
            jprio

            It's ok, it works fine, but I want to be able to use the values défined in the systemproperties-service.xml also !

            • 3. Re: @Resource and systemproperties-service.xml
              jaikiran

               

              "jprio" wrote:
              but I want to be able to use the values défined in the systemproperties-service.xml also !


              That's a bit tricky actually. Because of the way the deployers work in AS-5, the dependency jboss:type=Service,name=SystemProperties should actually be added on the deployer which parses the ejb-jar.xml into metadata, which from what i see is not straightforward.


              • 4. Re: @Resource and systemproperties-service.xml
                jaikiran

                I think there's a way out. Instead of specifying the properties in the deploy/systemproperties-service.xml file, you can instead have a MBean as follows in the JBOSS_HOME/server/< servername>/conf/jboss-service.xml:

                <!-- Jaikiran: Copied this SystemPropertiesService MBean from deploy folder -->
                 <mbean code="org.jboss.varia.property.SystemPropertiesService"
                 name="jboss:type=Service,name=MySystemProperties">
                
                
                 <attribute name="Properties">
                
                 serverName=blahblah
                
                
                 </attribute>
                
                 </mbean>


                That way, you don't have to worry about the deployment ordering and dependencies, since the conf/jboss-service.xml is always loaded during bootstrap of the server, before it picks up the deployments.


                • 5. Re: @Resource and systemproperties-service.xml
                  jprio

                  Thanx for the answer. Looks like it works !
                  The only remaining little problem is that we used to have a per-webapp systemproperties-service, which seems not to be possible anymore.