jakarta-eeejbcdiejb-jar.xml

Is it possible to use ejb annotation and CDI in a legacy project where all the existing EJB are configured in ejb-jar.xml


There is a legacy code base with the oldest EJB, where all the existing EJBS are configured in ejb-jar.xml

<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">
    <session>
        <ejb-name>ABean</ejb-name>
        <home>com.bla.api.RemoteBeanHome</home>
        <remote>com.bla.api.RemoteBean</remote>
        <ejb-class>com.bla.api.ABean</ejb-class>
        <session-type>Stateless</session-type>
        <transaction-type>Container</transaction-type>
    </session>
....

This works by means of searching through JNDI. However, the server was upgraded to Weblogic 12.2, where Java EE 7 is supported. So when injecting new local EJB to the remote session bean, ABean, I am thinking of using merely annotation, @EJB, without touching the existing XML deployment descriptor.

However, there is the following error:

The ejb-ref does not have an ejb-link and the JNDI name of the target bean has
not been specified. Attempts to automatically link the ejb-ref to its target 
bean failed because no EJBs in the application were found to implement the
"com.bla.api.NewBean" interface. Link or map this ejb-ref to its target EJB 
and ensure the interfaces declared in the ejb-ref are correct.

The new local stateless ejb code is the following:

@Stateless
public class TestEJB {
    public void test() {
        System.out.println("I am the first EJB injected with CDI");
    }
}

Question: In this case, is it still possible to add new EJBs with annotation instead of ejb-jar.xml?


Solution

  • I am affraid, that this little tag in your deployment descriptor version="2.1" tells the application server that your application is a Java EE 2.1 application and it will handle it accordingly. All the new spec features will not be available. Also I am affraid that the step from Java-EE 2 to 5 was so big, that you will not be able to make your app an JavaEE 5+ Application without code changes. I mean all the boiler plate code that was removed in Java EE 5 (Home, Remote, etc. interfaces) seems to be still inside your project. But I may be wrong, I am not so old, started working with JEE in version 5.