9 Replies Latest reply on Apr 11, 2007 2:46 PM by doktora

    @EJB annotation injection broken in 4.0.5.GA

    doktora

      Has anyone had this problem?

      I just ported an app to 4.0.5.GA and none of the @EJB annotations inject their beans.
      I've searched in jira/forum/google and have found only one other place where someone reported this problem on the sun developers forums.

      regards
      --doktora

        • 1. Re: @EJB annotation injection broken in 4.0.5.GA
          asack

           

          "doktora" wrote:
          Has anyone had this problem?

          I just ported an app to 4.0.5.GA and none of the @EJB annotations inject their beans.
          I've searched in jira/forum/google and have found only one other place where someone reported this problem on the sun developers forums.

          regards
          --doktora



          Litte bit more context and an example?

          • 2. Re: @EJB annotation injection broken in 4.0.5.GA
            mimra

            I have seen the same thing. Porting a working application from 4.0.4 to 4.0.5 and the @EJB injections no longer work.

            I don't know what else to say; it's an EJB3 application with stateless session beans...

            Regards
            Michael

            • 3. Re: @EJB annotation injection broken in 4.0.5.GA
              bdecoste

              There aren't any known issues with @EJB injection in 4.0.5 w/EJB3 RC9 Patch 1. Please post an example.

              • 4. Re: @EJB annotation injection broken in 4.0.5.GA
                doktora

                I've been testing two aspects: stateless beans and MBeans.

                Here is all the code:


                SomeBean -- stateless bean, it will be injected into TestBean.

                package test;
                
                @javax.ejb.Stateless
                @javax.ejb.Local(SomeIntr.class)
                public class SomeBean implements SomeIntr
                {
                 public String test() {
                 System.out.println("SomeBean::test()");
                 return "SomeBean::test()";
                 }
                }



                TestBean -- a steless bean which has SomeBean injected, I have tried to clarify EJB with beanName, etc. -- same effect. In 4.0.5.GA this prints "Hello: null".
                package test;
                
                @javax.ejb.Stateless
                @javax.ejb.Local(TestIntr.class)
                public class TestBean implements TestIntr
                {
                 @javax.annotation.EJB
                 SomeIntr some;
                
                 public void hello() {
                 System.out.println("Helllo: " + some);
                 if(some!=null) some.test();
                 }
                }


                This an MBean which tries to access TestBean in a few different ways -- injection, lookup, etc.

                Calling testme() on this mbean prints "TEST ME: null / null".
                Then after lookup and the call ti.hello() also prints "Helllo: null".
                package test;
                
                import javax.management.ObjectName;
                import javax.management.MBeanServer;
                import javax.management.MBeanRegistration;
                import javax.annotation.EJB;
                import javax.naming.InitialContext;
                import javax.naming.Context;
                import org.jboss.annotation.ejb.Service;
                
                
                public class TestService implements TestServiceMBean, MBeanRegistration
                {
                
                 @EJB //(beanName="data/TestBean/local")
                 TestIntr test;
                
                 TestIntr test2;
                
                 @EJB //(beanName="data/TestBean/local")
                 public void setTest(TestIntr ti) { test2 = ti; }
                
                 public void testme()
                 {
                 System.out.println("TEST ME: " + this.test + " / " + this.test2);
                
                 try {
                 InitialContext ctx = new InitialContext();
                 TestIntr ti = (TestIntr)ctx.lookup("data/TestBean/local");
                 System.out.println("TestIntr via lookup: " + ti);
                 ti.hello();
                
                
                 } catch(Exception e) {
                 System.out.println("Could not lookup TestIntr: " + e.getMessage());
                 e.printStackTrace();
                 }
                 }
                
                 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
                 System.out.println("TestService ::::::::::::: preRegister");
                 return name;
                 }
                
                 public void postRegister(Boolean registrationDone) {
                 System.out.println("TestService ::::::::::::: postRegister");
                 }
                
                 public void preDeregister() throws Exception {
                 System.out.println("TestService ::::::::::::: preDeregister");
                 }
                
                 public void postDeregister() {
                 System.out.println("TestService ::::::::::::: postDeregister");
                 }
                
                 public void start() throws Exception {
                 System.out.println("TestService ::::::::::::: start: " + this.test);
                 testme();
                 }
                 public void stop() throws Exception {
                 System.out.println("TestService ::::::::::::: stop");
                 }
                }
                



                For completeness, here are the corresponding interfaces:

                package test;

                public interface SomeIntr
                {
                 public String test();
                }


                TestBean interface:
                package test;
                
                public interface TestIntr
                {
                 public void hello();
                }


                TestService interface

                package test;
                
                import org.jboss.annotation.ejb.Management;
                
                public interface TestServiceMBean
                {
                 public void testme();
                
                 public void start() throws Exception;
                 public void stop() throws Exception;
                
                }


                To test this, I executed TestService.testme() from the JMX console.


                Here are some more JBoss details:

                [Server] Release ID: JBoss [Zion] 4.0.5.GA (build: CVSTag=Branch_4_0 date=200610162339)
                [Server] Server Name: default
                [Server] Root Deployment Filename: jboss-service.xml
                [ServerInfo] Java version: 1.5.0_07,Apple Computer, Inc.
                [ServerInfo] Java VM: Java HotSpot(TM) Server VM 1.5.0_07-87,"Apple Computer, Inc."
                [ServerInfo] OS-System: Mac OS X 10.4.9,i386



                And this is from jboss-service.xml:
                 <mbean code="clairetest.TestService" name="clairetest:service=testservice">
                 </mbean>


                Let me know if further info would be of use and if anyone can confirm this.

                As I mentioned, JB405 was installed in EJB3-clustered mode via the jems installer.

                --doktora

                • 5. Re: @EJB annotation injection broken in 4.0.5.GA
                  doktora

                  Small error in the jboss-service.xml: it should be test.TestService

                  • 6. Re: @EJB annotation injection broken in 4.0.5.GA
                    wolfc

                    @javax.annotation.EJB should be @javax.ejb.EJB

                    http://jira.jboss.com/jira/browse/EJBTHREE-608

                    • 7. Re: @EJB annotation injection broken in 4.0.5.GA
                      doktora

                      I think I may spot the problem after reviewing my build.xml -- I was linking to libraries in 4.0.4 where you can find jboss-ejb3x.jar which contains javax.annotations.EJB.

                      In 4.0.5 javax.annotations.EJB is nowhere to be found. Where is it?

                      I haven't confirmed that this is the problem, because I haven't yet managed to compile against 4.0.5.

                      • 8. Re: @EJB annotation injection broken in 4.0.5.GA
                        doktora

                         

                        "wolfc" wrote:
                        @javax.annotation.EJB should be @javax.ejb.EJB

                        http://jira.jboss.com/jira/browse/EJBTHREE-608


                        Brilliant, let me try....

                        • 9. Re: @EJB annotation injection broken in 4.0.5.GA
                          doktora

                           

                          "wolfc" wrote:
                          @javax.annotation.EJB should be @javax.ejb.EJB

                          http://jira.jboss.com/jira/browse/EJBTHREE-608



                          This was the culprit!!!

                          I've been looking for JBoss 404->405 migration guides. I should have looked for EJB migration guides:

                          http://wiki.jboss.org/wiki/Wiki.jsp?page=FromRC8RC9

                          References to javax.annotation.EJB must be changed to javax.ejb.EJB for proper injection. javax.ejb.EJB lives in RC9's jboss-ejb3x.jar. When running the patch installer, this file gets updated in $JBOSS_HOME/server/instancename?/deploy/ejb3.deployer, but not $JBOSS_HOME/client at time of this writing.


                          Thanks wolfc!