1 Reply Latest reply on Oct 18, 2011 2:14 PM by Arend v. Reinersdorff

    Constructor Injection for EJB does not work

    Arend v. Reinersdorff Newbie

      Hi,

       

      I have the following EJB:

       

      {code}

      @Stateless

      public class GreeterBean {

       

          private Greeter greeter;

       

       

          @Inject

          public GreeterBean(Greeter greeter) {

              this.greeter = greeter;

          }

       

       

          public String greet() {

              return greeter.getGreeting();

          }

      }

      {code}

       

      When I invoke it I get the following exception:

       

      {code}

      Caused by: org.jboss.weld.exceptions.WeldException: WELD-000033 Could not instantiate client proxy for Session bean [class com.example.GreeterBean with qualifiers [@Any @Default]; local interfaces are [GreeterBean]

          at org.jboss.weld.bean.SessionBean.create(SessionBean.java:349) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

          at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:67) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

          at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:693) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

          at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:731) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

          at org.jboss.resteasy.cdi.CdiConstructorInjector.construct(CdiConstructorInjector.java:65) [resteasy-cdi-2.2.1.GA.jar:]

          at org.jboss.resteasy.cdi.CdiConstructorInjector.construct(CdiConstructorInjector.java:70) [resteasy-cdi-2.2.1.GA.jar:]

          at org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory.createResource(POJOResourceFactory.java:43) [resteasy-jaxrs-2.2.1.GA.jar:]

          at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:208) [resteasy-jaxrs-2.2.1.GA.jar:]

          at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:519) [resteasy-jaxrs-2.2.1.GA.jar:]

          ... 23 more

      Caused by: java.lang.InstantiationException: com.example.GreeterBean$Proxy$_$$_Weld$Proxy$

          at java.lang.Class.newInstance0(Unknown Source) [:1.7.0]

          at java.lang.Class.newInstance(Unknown Source) [:1.7.0]

          at org.jboss.weld.util.reflection.SecureReflections$16.work(SecureReflections.java:395) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

          at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

          at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInstantiation(SecureReflectionAccess.java:216) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

          at org.jboss.weld.util.reflection.SecureReflections.newInstance(SecureReflections.java:390) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

          at org.jboss.weld.bean.SessionBean.create(SessionBean.java:338) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

          ... 31 more

      {code}

       

       

      The example works fine with method or field injection, just not with constructor injection. The example works fine in Glassfish 3.1.1.

       

      Is this a bug or am I missing something?

       

      Best regards,

      Arend