4 Replies Latest reply on Aug 4, 2012 4:24 PM by snelders

    resource-env-ref-name doesn't work correctly

    snelders

      Deploying a simple war with the following web.xml in JBoss 7.1 will fail:

       

      {code:xml}

      <web-app>

      .....

              <resource-env-ref id="config-location">

                          <resource-env-ref-name>some/entry/name</resource-env-ref-name>

                          <resource-env-ref-type>java.lang.String</resource-env-ref-type>

                </resource-env-ref>

       

                <env-entry>

                          <env-entry-name>some/entry/name</env-entry-name>

                          <env-entry-type>java.lang.String</env-entry-type>

                          <env-entry-value>some string value</env-entry-value>

                </env-entry>

      </web-app>

      {code}

       

      JBoss throws the following exception during deployment:

       

      MSC00001: Failed to start service jboss.deployment.subunit."simple.war".

      ...

      Caused by: java.lang.IllegalArgumentException: JBAS011053: Incompatible conflicting binding at java:module/env/some/entry/name source: org.jboss.as.ee.component.LookupInjectionSource@c12f7d68

                at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:237)

       

      However adding a prefix "java:comp/env/" or "java:module/env/" to the resource-env-ref-name value fixes the problem.

       

      {code:xml}

      <web-app>

      .....

      <resource-env-ref-name>java:comp/env/some/entry/name</resource-env-ref-name>

      ....

      </web-app>

      {code}

       

      However, the deployment failure complaining about the incorrect resource-env-ref-name seems incorrect. According to the servlet 3 specs: "The resource-env-ref-name ... value is ... relative to the java:comp/env".

      I would have expected that deployment would work in case I specify the resource-env-ref-name without a "java:comp/env/" or "java:module/env/" prefix.

       

      In my case I have to deploy to multiple different application servers (like WebSphere) which work according to the specs. This forces me to generate multiple web.xml's which is a little bit annoying.

       

      My question: Is this a bug or is this me doing something wrong?

        • 1. Re: resource-env-ref-name doesn't work correctly
          cfang

          If the config data type is java.lang.String (or any other primitive types), just use <env-entry>.  Do not use <resource-env-ref> or <resource-ref>, both are intended for more complex resources like jdbc or jms.

           

          Any reason you have to use the conflicting names?  Whether you prefix it or not, they are still conflicting names.  The reason it worked in some case is probably the validaton is not triggered but it may ultimately fail down the road.

           

          My suggestion would be to fix the application web.xml.  This is the only way to achieve consistent  and compatible results across differnet servers.

          • 2. Re: resource-env-ref-name doesn't work correctly
            snelders

            On second thought I still think the "Incompatible conflicting binding" error shouldn't be there.


            A small note on what I actually try to achieve here (since I oversimplified my example):

            Environment

            • Local development server is JBoss/Jetty (deploy frequently)
            • Remote development server is WebSphere (deploy occasionally)

             

            Setup

            • In web.xml I define the resource-env-ref entries. (I would like the deployment to fail if the refered references are not present)
            • In jboss-web.xml I define the env-entries. Which makes it easy to frequently change the values during development (or just install another JBoss version).
              (For Jetty there is a jetty-env.xml with an equivalent of env-entry records)
            • In Websphere the resource-env-ref values are server side defined as name space bindings (the same way as the production environment).

             

            In my opinion the env-entry should just be handled as a simple binding as in standalone.xml:

             

            <subsystem xmlns="urn:jboss:domain:naming:1.1" >

              <bindings>

                <simple name="java:global/some/entry/name" value="some string value" />

            </bindings>

            </subsystem>

             

            There should only be a conflict once there are two bindings defined with the same name. The resource-env-ref tag doesn't count since it is only a reference (it doesn't define any value)

            • 3. Re: resource-env-ref-name doesn't work correctly
              cfang

              Whether you use <env-entry>, <resource-env-ref>, <resource-ref>, or <ejb-ref>, they are all reference names in a single namespace belonging to your webapp, hence the conflict. 

               

              some/entry/name, is the same as java:comp/env/some/entry/name, and is also the same as java:module/env/some/entry/name, for reference resolution purpose.

               

              Not sure I completely understand your use case, but I would declare a <env-entry>, mapping it to a global jndi name with <lookup-name> or <mapped-name>.  So you app always looks up or injects the same ref name, and different server can create this global resource differently.

              • 4. Re: resource-env-ref-name doesn't work correctly
                snelders

                Ok thanks for the explanation Cheng.

                 

                Simply put I just need a way to define a value for a resource-env-ref of type java.lang.String directly in a deployment descriptor.

                Is there a possibility to do this somehow in JBoss? (without replacing resource-env-ref with env-entry)