1 Reply Latest reply on Aug 14, 2012 3:05 AM by ole .

    Overwrite Annotation by using ejb-jar.xml not working

    ole . Newbie



      In my application I have an interface that is implemented by 2 classes (mock, productive). Due to the fact I need the mock also during my deployment for testing I have both implementations in my ejb package.

      When I try to inject one of these implementations I set the "beanName" property of @EJB to decide which implementation should be injected:


      @EJB(beanName = "MyInterfaceImpl1")
      MyInterface myInterface;


      If I want to use another implementation for this injection I'm using the ejb-jar.xml to overwrite the beanName:


      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">


      This is working properly during a deployment on Glassfish 3.1. Instead of MyInterfaceImpl1 MyInterfaceImpl2 i used.

      Unfortunatly this is not working in Arquillian. I'm building an archive, adding the ejb-jar.xml and run the test, but the MyInterfaceImpl1 will be injected instead of MyInterfaceImpl2 wich results in a failing test.

      I build my arquillian archive like this:


        public static WebArchive createDeployment() {
          WebArchive archive = ShrinkWrap
              .create(WebArchive.class, "test.war")
              .addClasses(MyEJBean.class, MyInterface.class,
              .addAsWebInfResource("ejb-jar-test.xml", "ejb-jar.xml");
          return archive;