2 Replies Latest reply on Mar 2, 2006 8:03 PM by bill.burke

    Injecting a String

    fcorneli

      In my MDB I have:

      @Resource(mappedName = "TheStringResource")
      private String theStringResource;
      

      I also have a resource-env-ref in both my ejb-jar.xml and jboss.xml. But when onMessage is invoked it gives me null for the value of the 'theStringResource' variable. And this while:
      String value = new InitialContext().lookup("TheStringResource");
      

      is retrieving the correct value. Isn't is possible to inject Strings via @Resource or am I doing something wrong here? Using 4.0.4RC1.

        • 1. Re: Injecting a String
          bdecoste

          To inject a String, use this:


          @Resource(name = "TheStringResource")
          private String theStringResource;

          <enterprise-beans>

          <ejb-name>ejb-name</ejb-name>
          <env-entry>
          <env-entry-name>TheStringResource</env-entry-name>
          <env-entry-type>java.lang.String</env-entry-type>
          <env-entry-value>value</env-entry-value>
          </env-entry>

          • 2. Re: Injecting a String
            bill.burke

            env-entry also supports the injection-target element