1 2 Previous Next 24 Replies Latest reply on Dec 4, 2006 9:41 AM by jahlborn

    EJB 3.0 and env-entry injection

    czertik

      Hi,

      after a lot of fruitless experimentation and JBoss code reading I came to the conclusion, that env-entry @Resource injection does not work currently - specifically, I could not find any code that would bind the entries into JNDI, so that they can be injected from java:comp/env as supposed.

      Could anyone prove me right, or kick me in the right direction?

      According to spec, this shoud work:

      ...
      public class ... {
      ...
      @Resource String providerURL;
      ...
      }
      


      with this code in the ejb-jar.xml:

      ...
      <env-entry>
       <env-entry-name>providerURL</env-entry-name>
       <env-entry-type>java.lang.String</env-entry-type>
       <env-entry-value>ldap://localhost:389/</env-entry-value>
      </env-entry>
      ...
      


      Instead, I have
      22:43:04,483 WARN [ServiceController] Problem starting service jboss.j2ee:service=EJB3,name=DirContextServiceBean
      javax.naming.NameNotFoundException: providerURL not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:249)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       ....
      


      Any ideas?

        • 1. Re: EJB 3.0 and env-entry injection
          onekludov

          I have same problem to...

          • 2. Re: EJB 3.0 and env-entry injection
            viennec

            I also already tried out plenty of things (explicit adding name property to annotation, prefixing in the ebj-jar.xml the env-entry-name value with the package and Bean name, ...) and none seems to work.

            • 3. Re: EJB 3.0 and env-entry injection
              bill.burke

              Ok, revamped this stuff in RC3 release...

              You do need to read Java EE 5 specification on injection. According to specification, your above code would not work...It needs to be:

              
              package org.acme;
              
              public class MyClass {
              
              @Resource(name="providerURL") String field;
              
              <env-entry>
               <env-entry-name>providerURL</env-entry-name>
               <env-entry-type>java.lang.String</env-entry-type>
               <env-entry-value>ldap://localhost:389/</env-entry-value>
              </env-entry>
              


              OR

              
              package org.acme;
              
              public class MyClass {
              
              @Resource String field;
              
              
              <env-entry>
               <env-entry-name>org.acme.MyClass/field</env-entry-name>
               <env-entry-type>java.lang.String</env-entry-type>
               <env-entry-value>ldap://localhost:389/</env-entry-value>
              </env-entry>
              
              


              OR

              package org.acme;
              
              public class MyClass {
              
              String field;
              
              
              <env-entry>
               <env-entry-name>providerUrl</env-entry-name>
               <env-entry-type>java.lang.String</env-entry-type>
               <env-entry-value>ldap://localhost:389/</env-entry-value>
               <injection-target>
               <injection-target-class>org.acme.MyClass</injection-target>
               <injection-target-name>field</injection-target-name>
               </injection-target>
              </env-entry>
              


              All this should work in RC3 now...

              • 4. Re: EJB 3.0 and env-entry injection
                viennec

                I'm sorry but after upgrading my JBoss 4.0.3 AS with the EJB 3.0 RC3 release, i have the impression only the last case works (using the injection-target tag) while the other 2 possibilities mentioned still don't work (a bit pitty since i find these in fact the nicest ways to inject)
                Anyway, at least now there's a way to inject an environment entry, so thanks!

                christophe

                • 5. Re: EJB 3.0 and env-entry injection
                  bill.burke

                  I thought I had the appropriate junit tests... I do have a test for #2 and #3 above, but not #1. Can you post how #2 does not work?

                  • 6. Re: EJB 3.0 and env-entry injection
                    czertik

                    I can confirm, that from the examples above only the third is working in my environment as well - installed JBoss 4.0.3 + EJB 3.0 RC3.

                    The first example seems to bind the entries to the NamingContext, but there's no interceptor created for the injection. The second is unable to find the field for injection - no wonder, when it really uses the whole string in the tag.

                    As soon as I find some spare time, I'll try to debug it some more and hopefully provide more insight or even patch if possible... but I'm just too deep in other stuff right now :-(

                    • 7. Re: EJB 3.0 and env-entry injection
                      jagthedrummer

                      Can someone please post a full example of the ejb-jar.xml file where this is working? I've spent hours trying to get it to work, and no matter what I do I can't seem to get an env-entry passed into one of my classes. I assume that it's supposed to go inside the entry for a particular bean, but it's just not working for me at all. I'm attempting to do option #3 as mentioned above since it's the version that people have gotten to work.

                      Thanks,
                      Jeremy

                      • 8. Re: EJB 3.0 and env-entry injection
                        bill.burke

                        Jag/Jeremy,

                        You need to publish examples of what exactly is going wrong.

                        • 9. Re: EJB 3.0 and env-entry injection
                          jagthedrummer

                          What's going wrong is that none of the examples given above seem to work, and I'm wondering where exactly all that information needs to go. Having the java code mixed in with the deployment descriptor doesn't really give me an idea where in the deployment descriptor the env-entry stuff should go.

                          I have a class that looks like this:

                          package com.webeprint.node.ejb;
                          
                          @Service
                          public class NodeManagerBean implements NodeManager {
                           String testParam = "origTestParam";
                          }
                          


                          Then I'm setting up ejb-jar.xml to look like this:

                          <ejb-jar>
                           <enterprise-beans>
                           <session>
                           <ejb-name>com.webeprint.node.ejb.NodeManager</ejb-name>
                           <ejb-class>com.webeprint.node.ejb.NodeManagerBean</ejb-class>
                           <env-entry>
                           <env-entry-name>testParam</env-entry-name>
                           <env-entry-type>java.lang.String</env-entry-type>
                           <env-entry-value>newTestValue</env-entry-value>
                           <injection-target>
                           <injection-target-class>com.webeprint.node.ejb.NodeManagerBean</injection-target-class>
                           <injection-target-name>testParam</injection-target-name>
                           </injection-target>
                           </env-entry>
                           </session>
                           </enterprise-beans>
                          </ejb-jar>
                          
                          


                          I've tried this too:
                          <ejb-jar>
                           <enterprise-beans>
                           <session>
                           <ejb-name>com.webeprint.node.ejb.NodeManagerBean</ejb-name>
                           <ejb-class>com.webeprint.node.ejb.NodeManagerBean</ejb-class>
                           <env-entry>
                           <env-entry-name>testParam</env-entry-name>
                           <env-entry-type>java.lang.String</env-entry-type>
                           <env-entry-value>newTestValue</env-entry-value>
                           <injection-target>
                           <injection-target-class>com.webeprint.node.ejb.NodeManagerBean</injection-target-class>
                           <injection-target-name>testParam</injection-target-name>
                           </injection-target>
                           </env-entry>
                           </session>
                           </enterprise-beans>
                          </ejb-jar>
                          
                          



                          I've even tried this (which I didn't really expect to work, but I'll try anything at this point):

                          <ejb-jar>
                           <enterprise-beans>
                           <env-entry>
                           <env-entry-name>testParam</env-entry-name>
                           <env-entry-type>java.lang.String</env-entry-type>
                           <env-entry-value>newTestValue</env-entry-value>
                           <injection-target>
                           <injection-target-class>com.webeprint.node.ejb.NodeManagerBean</injection-target-class>
                           <injection-target-name>testParam</injection-target-name>
                           </injection-target>
                           </env-entry>
                          
                           </enterprise-beans>
                          </ejb-jar>
                          
                          


                          I also tried many variations of examples #1 and #2, and none of them can get the job done. What I need is:

                          testParam.equals("newTestValue") == true;
                          


                          All I ever end up with is :


                          testParam.equals("origTestParam") == true;
                          


                          I even tried leaving testParam unintialized in my class, but I just get a NullPointerException when trying to test the value of it.

                          So, I'm hoping that someone can post the full code for a simple class and ejb-jar.xml file that actually gets this to work.

                          Thanks,
                          Jeremy

                          • 10. Re: EJB 3.0 and env-entry injection
                            sandello

                            IMHO, you forget annotation "@Resource" before

                            String testParam = "origTestParam";
                            


                            It exist in example 1 and 2

                            • 11. Re: EJB 3.0 and env-entry injection
                              jagthedrummer

                               

                              "sandello" wrote:
                              IMHO, you forget annotation "@Resource" before
                              String testParam = "origTestParam";
                              


                              It exist in example 1 and 2


                              Yeah, I got the impression that you didn't need it when you're using the injection-target method (#3). But I'm pretty sure that I tried it that way anyway. I'll give it another shot and see what I can come up with.

                              Jeremy

                              • 12. Re: EJB 3.0 and env-entry injection
                                jagthedrummer

                                 

                                "sandello" wrote:
                                IMHO, you forget annotation "@Resource" before
                                String testParam = "origTestParam";
                                


                                It exist in example 1 and 2


                                I just tested it again, and if I use the @Resource I get an exception thrown about testParam not being bound.

                                Jeremy


                                • 13. Re: EJB 3.0 and env-entry injection
                                  bill.burke

                                  1) You should not need the @Resource annotation
                                  2) Can you please post stack traces. "I get an exception" does not help us very much in debugging your problem.

                                  • 14. Re: EJB 3.0 and env-entry injection
                                    jagthedrummer

                                     

                                    "bill.burke@jboss.com" wrote:
                                    1) You should not need the @Resource annotation
                                    2) Can you please post stack traces. "I get an exception" does not help us very much in debugging your problem.


                                    But I only get the exception when I include the @Resource (which you siad I don't need). When I leave that out there is no exception. No nothing. It just flat out doesn't work, doesn't complain, doesn't even act like it's trying to work. I do get a line like this:

                                    [org.jboss.ejb3.Ejb3DescriptorHandler] found ejb-jar.xml jar:file:/usr/local/jboss-4.0.3RC2/server/default/tmp/deploy/tmp57478testclient-webeprint.ejb3!/META-INF/ejb-jar.xml
                                    


                                    But that doesn't seem like it's going to tell anyone anything.

                                    I wish there was more information I could give you but I simply don't have it. So again, if someone could please post a FULL example of a simple class and ejb-jar.xml file that actually does work, maybe I can use that to figure out what's going on.

                                    Thanks,
                                    Jeremy


                                    1 2 Previous Next