4 Replies Latest reply on Nov 14, 2011 2:17 PM by Noah White

    Use of beans.xml for EJb archive

    Vicky . Newbie

      I was testing EJB examples published in Enterprise JavaBeans 3.1 (from Oreilly) book. After lot of tweaking here and there, I got it running with JBoss AS 6.


      One strange thing that I noticed is that even for EJB deployment, I had to add a beans.xml file in Ejb jar (as shown below).



         public static JavaArchive createDeployment() throws MalformedURLException


            final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "firstejb.jar").addPackage(



            return archive;



      If I do not add this, then JBoss AS throws error at the time of deployment (See below..the highlighted lines):


      08:26:02,093 WARN  [org.jboss.ejb3.TimerServiceContainer] EJBTHREE-2193: using deprecated TimerServiceFactory for restoring timers

      08:26:02,109 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] deploy, ctxPath=/test

      08:26:02,968 INFO  [org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher]


      BeanManager cannot be located at java:comp/BeanManager. Either you are using an archive with no beans.xml, or the BeanManager has not been bound to that location in JNDI.


      08:26:03,000 INFO  [org.jboss.profileservice.management.upload.remoting.DeployHandler] invoke, payload: {DeploymentTargetID=names=[test.war], clientAddress=/127


      ------------- -------------------- -------------------- -------------------------- ----------------------- --------------- ------------------------ -----------------------------------------


      My question is, do we need to add beans.xml for EJB deployment? I'm confused because the example published on Arquillian refernce doc doesn't add this file.


      I'm attaching POM File, My EJB Bean class and IntegrationTest class for reference.

        • 1. Re: Use of beans.xml for EJb archive
          Aslak Knutsen Master

          You don't hvae to add a beans.xml for it to work. Arquillian has multiple Enrichers for doing the Injection on a TestClass, EJB, Resource and CDI.


          They are all added to the deployment and will attempt to run on JBoss AS 6. The message your seeing is not a Exception, it's just the CDIEnricher that says; I can't find a BeanManager, so if you intended to use CDI features in your testcase, your probably missing beans.xml or something else is wrong.


          It's basically just to chatty..

          • 2. Re: Use of beans.xml for EJb archive
            Vicky . Newbie

            If I remove the source code for adding "beans.xml", my test cases are failing and this is what I could see in eror log. What am I doing wrong here?


            One thing I did notice is that, Arquillian is deploying my application with name "test.war", see below message on JBoss console:


            22:21:03,578 INFO  [org.jboss.profileservice.management.upload.remoting.DeployHandler] invoke, payload: {DeploymentTargetID=names=[test.war], clientAddress=/}, parameter: start


            *****************************ERROR TRACE BELOW************************************

            Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.641 sec <<< FAILURE!

            testAdditionUsingBusinessReference(org.jboss.ejb3.examples.ch04.firstejb.CalculatorIntegrationTestCase)  Time elapsed: 0.062 sec  <<< ERROR!

            java.lang.RuntimeException: Could not inject members

                at org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher.injectClass(EJBInjectionEnricher.java:138)

                at org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher.enrich(EJBInjectionEnricher.java:50




            Caused by: javax.naming.NamingException: No EJB found in JNDI, tried the following names: java:global/test.ear/test/CalculatorLocalBusinessBean, java:global/test.ear/test/CalculatorLocalBusiness, java:global/test/CalculatorLocalBusiness, java:global/test/CalculatorLocalBusinessBean, java:global/test/CalculatorLocalBusiness/no-interface, test/CalculatorLocalBusinessBean/local, test/CalculatorLocalBusinessBean/remote, test/CalculatorLocalBusiness/no-interface, CalculatorLocalBusinessBean/local, CalculatorLocalBusinessBean/remote, CalculatorLocalBusiness/no-interface,

                at org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher.lookupEJB(EJBInjectionEnricher.java:179)

                at org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher.injectClass(EJBInjectionEnricher.java:103)

            • 3. Re: Use of beans.xml for EJb archive
              Aslak Knutsen Master

              There is no standard way of going from a EJBs Interface (InjectionPoint) to the JNDI Name, so Arquillian tries to guess on a couple of common naming strategies by default. You need to use @EJB.mappedName if you fall outside of those.



              • 4. Re: Use of beans.xml for EJb archive
                Noah White Newbie

                I know your @Deployment method returns a JavaArchive but I also noticed this info message:


                08:26:03,000 INFO  [org.jboss.profileservice.management.upload.remoting.DeployHandler] invoke, payload: {DeploymentTargetID=names=[test.war], clientAddress=/127


                That INFO message mentions test.war. I ran into a case when using Arquillian with GF 3.1 where I was trying to test a some EJBs and ran into the same symptoms you described. That is the test would only deploy if I included a beans.xml file.


                My original @Deployment method was returning a WebArchive with a web.xml included.  However, I found that if I removed the web.xml and changed it to return a JarArchive my test would deploy and run without a beans.xml file. It seems if you package as a WAR Arquillian needs to use the CDI enricher to find things.