javajakarta-eejava-ee-6ejb-3.1ejb-2.x

EJB3 annotations get ignored when ejb-jar.xml is present


I have an application that currently consists of EJB 2.1 Session Beans. I want to transport them to EJB 3.1 annotations where possible.

Unfortunately that is not possible for all so I need to maintain the ejb-jar.xml file for the ones where I can't use the annotations.

I have added the beans.xml file but as long as I have the ejb-jar.xml file present, the annotations are ignored. As soon as I remove it, the annotations work.

How can I configure my application to use the annotations where present and use the ejb-jar.xml file only for stuff thats configured inside it. As far as I understood the documentation, this should be the normal case anyway.


Solution

  • When you shift your application from EJB-2.1 to EJB-3.1 you have to check that you set the version of the ejb-jar.xml to 3.1 as well.

    Use this header from the the xsd:

    <ejb-jar 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_1.xsd"
          version="3.1">
    

    Then your annotations are considered then as well.

    The beans.xml is not needed for this at all. It is required for enabling CDI (which you don't need if you only refer to your beans from other beans), have a look at this post about what it is and when you need it.

    You might need other settings to your ejb-jar.xml as well but that is a topic for another question.