1 2 Previous Next 25 Replies Latest reply on Feb 12, 2010 1:16 PM by nickarls

    Message Driven Beans can't be Managed Beans

    heri

      As soon as I add a message-driven bean (just an empty class annotated with @MessageDriven, not referenced anywhere) to a JEE 6 project (already working with CDI), I cannot deploy it in Glassfish 3 because of the following exception:


      org.glassfish.deployment.common.DeploymentException: Message Driven Beans can't be Managed Beans
           at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:169)
           at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:125)
           at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:224)
           at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:338)
           at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
           at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
           at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
           at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
           at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
           at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
           at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
           at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
           at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
           at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
           at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
           at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
           at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
           at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
           at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
           at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
           at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
           at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
           at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
           at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
           at java.lang.Thread.run(Thread.java:619)
      Caused by: org.jboss.weld.DefinitionException: Message Driven Beans can't be Managed Beans
           at org.jboss.weld.bean.SessionBean.checkEJBTypeAllowed(SessionBean.java:313)
           at org.jboss.weld.bean.SessionBean.initialize(SessionBean.java:122)
           at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:111)
           at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:151)
           at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:367)
           at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:167)
           ... 30 more


      I have already read a lot of documentation, but I still cannot understand why this error occurs. Any hint what I'm doing wrong?

        • 1. Re: Message Driven Beans can't be Managed Beans
          nickarls

          The message is correct

          • 2. Re: Message Driven Beans can't be Managed Beans
            heri

            I do not doubt this. My question is, how can I use message-driven beans in a JEE 6 project with CDI enabled? See calling a bean from a message-driven bean in the Weld documentation, how can I get that concrete example to work, if I cannot deploy a message-driven bean because of the error message above?

            • 3. Re: Message Driven Beans can't be Managed Beans
              meetoblivion

              are you actually decorating it @ManagedBean or @Named ? If so, just leave those off and leave the MDB @MessageDriven and implements MessageListener.

              • 4. Re: Message Driven Beans can't be Managed Beans
                heri

                If I would use such annotations, I would understand the error. No, I'm using a simple class annotated with @MessageDriven, no other annotations. Even a minimal class like this causes the error:


                @MessageDriven(mappedName = "jms/myQueue")
                public class Foo 
                {
                  // implementing MessageListener makes no difference
                }



                • 5. Re: Message Driven Beans can't be Managed Beans
                  graben

                  For me it seems like a bug in the glassfish integration. If I read the spec right then MDBs are managed beans that can't be injected into other beans but it can be injected into themselves. Hopefully Gavin can give a proper answer to that behavior!


                  Greets Benjamin

                  • 6. Re: Message Driven Beans can't be Managed Beans
                    nickarls

                    I interpret it as: MDB can't be managed beans. Managed beans are all beans in a managed bean archive. Presense of beans.xml in a deployment archive makes a managed bean archive. So, stick your MDB in a jar that doesn't have a beans.xml

                    • 7. Re: Message Driven Beans can't be Managed Beans
                      meetoblivion

                      Benjamin Graf wrote on Dec 20, 2009 09:35:


                      For me it seems like a bug in the glassfish integration. If I read the spec right then MDBs are managed beans that can't be injected into other beans but it can be injected into themselves. Hopefully Gavin can give a proper answer to that behavior!

                      Greets Benjamin


                      No, opposite.  MDB are not managed beans, but you can inject into them.  You can't inject an MDB into anything because of how they work architecturally.  If a client invokes something on the MDB directly, you suddenly lose what they're designed for - a messaging system.  You can however inject the queue that they subscribe to.  @Resource still works and the @Resource facade pattern is pretty fun


                      Nicklas' statement makes sense.  If I thought about it some more, I probably would have realized the OP seems to be creating an archive that has a beans.xml as well as MDBs.


                      It's annoying because JSR-299 very clearly states that all objects in the archive become managed beans when beans.xml is present.  I wish it said and we'll just ignore the ones that can't be managed beans instead of we'll choke if we come across a bad bean.

                      • 8. Re: Message Driven Beans can't be Managed Beans
                        graben

                        Okay I know found the code which is responsible for that behaviour in SessioBean.java



                        /**
                          * Validates the bean type
                          */
                          private void checkEJBTypeAllowed()
                          {
                             if (ejbDescriptor.isMessageDriven())
                             {
                                throw new DefinitionException("Message Driven Beans can't be Managed Beans");
                             }
                          }



                        But their is something left which I still do not understand. If MDBs are no managed bean which I think fits the rules of the managed bean spec you can't inject beans into them via CDI. Is their any technical reason or that? I think that is a unnecessary restriction.


                        • 9. Re: Message Driven Beans can't be Managed Beans
                          meetoblivion

                          It's a point where the spec gets a bit confusing.  You can actually inject into a MDB.  From the link above:




                          @Transactional @MessageDriven
                          public class ProcessOrder implements MessageListener {
                             @Inject Inventory inventory;
                             @PersistenceContext EntityManager em;
                          
                             public void onMessage(Message message) {
                                ...
                             }
                          }



                          • 10. Re: Message Driven Beans can't be Managed Beans
                            nickarls

                            John Ament wrote on Dec 20, 2009 16:50:

                            It's annoying because JSR-299 very clearly states that all objects in the archive become managed beans when beans.xml is present.  I wish it said and we'll just ignore the ones that can't be managed beans instead of we'll choke if we come across a bad bean.


                            I would assume Seam 3 will have an extension like org.jboss.seam.boostrap.LightenUpWillYa that just logs and vetos stuff it can't process

                            • 11. Re: Message Driven Beans can't be Managed Beans
                              gavin.king

                              As soon as I add a message-driven bean (just an empty class annotated with @MessageDriven, not referenced anywhere) to a JEE 6 project (already working with CDI), I cannot deploy it in Glassfish 3 because of the following exception:

                              That sounds like a bug in GlassFish or Weld.

                              • 12. Re: Message Driven Beans can't be Managed Beans
                                gavin.king

                                Nicklas Karlsson wrote on Dec 20, 2009 10:28:


                                I interpret it as: MDB can't be managed beans. Managed beans are all beans in a managed bean archive. Presense of beans.xml in a deployment archive makes a managed bean archive. So, stick your MDB in a jar that doesn't have a beans.xml


                                No, this should not be necessary.

                                • 13. Re: Message Driven Beans can't be Managed Beans
                                  gavin.king

                                  But their is something left which I still do not understand. If MDBs are no managed bean which I think fits the rules of the managed bean spec you can't inject beans into them via CDI. Is their any technical reason or that? I think that is a unnecessary restriction.

                                  You can. Injection is defined for:



                                  ...a bean class, or of any Java EE component class supporting injection.

                                  Where the phrase Java EE component class supporting injection is defined by the EE spec to include all EJBs, servlets, etc.


                                  So you can definitely inject into MDBs using CDI.

                                  • 14. Re: Message Driven Beans can't be Managed Beans
                                    nickarls

                                    BTW, is there anything in the spec that goes against my reasoning (or would allow for MDBs to just be ignored instead of trying to make them managed beans as all other stuff in the BDA)?

                                    1 2 Previous Next