1

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Rui
  • 3,454
  • 6
  • 37
  • 70

1 Answers1

0

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.

  • Thanks really really much for your answer. I makes great sense. What if I update all the `ejb-jar` tag in all the `ejb-jar.xml` around the whole multi-module project? Java is considerated to be backward compatible – Rui May 08 '20 at 14:09
  • Well, "Java" as language is backward compatible. "Java EE" is a specification which defines the contract between the Java EE application server and the Java EE application. Starting with Java EE 5 until Jakarta 8 you could really just update the version tag and your app would work with the new specification. My understanding is that JEE2 -> Java EE 5 was a breaking change. The Java EE 5 Spec eliminated a lot of boiler plate code i.e. home interfaces. So to move further you would have to change your code too. Depending on the complexity of your app this may or may not be possible... –  May 08 '20 at 17:09