Search code examples
jakarta-eeejbweblogic

Weblogic 12.2 ignore @EJB annotation


I'm migration an application from weblogic 10.3 to weblogic 12.2.

I include an library that is shared with other projects. This jar contains some POJOs with @EJB annotation in that look like this:

public abstract BaseSpecialService{
   @EJB DelegateService injectedService;
}

Note this is just a POJO: it doesn't have the @Stateless or @Stateful annotation. The idea is when I want to use this service, I extend it with a concrete @Stateless Bean class in another ejb-jar. But I only want to this for the services I need, the other services should be treated as POJOS.

In weblogic 10 this works just fine, but when moving to weblogic 12, I can't deploy the app because the container tries to inject the DelegateService in my example above, even though the @EJB annotation is not in an EJB but in a POJO. I get this error on deployment:

[J2EE:160200]Error resolving ejb-ref "com.example.BaseSpecialService/injectedService" from module "null" of application "myapp-0.1.0-SNAPSHOT". 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.example.DelegateService" interface. Link or map this ejb-ref to its target EJB and ensure the interfaces declared in the ejb-ref are correct.

My interpretation is that in java EE 7 the all jars get scanned for annotations, while in java EE 5, only the jars that are marked as ejb modules in the application.xml get scanned. I'm looking for a way to stop the application server to inject dependencies into my POJOs and treat the shared library jar as a normal jar, not as an ejb-jar. But I can't find anything to do this. Any help is much appreciated.


Solution

  • Seems the CDI container of the WebLogic scans your jar file and tries to inject POJOs/EJBs into them. My suggestion is to disable CDI scanning for given jar files and see the result. You can do this by adding a file named beans.xml containing following content and put it in the META-INF folder of your jar file:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
        version="1.1" bean-discovery-mode="none">
    </beans>