Weblogic 12.2 忽略@EJB 注解

Weblogic 12.2 ignore @EJB annotation

我正在将应用程序从 weblogic 10.3 迁移到 weblogic 12.2。

我包括一个与其他项目共享的库。这个 jar 包含一些带有 @EJB 注释的 POJO,看起来像这样:

public abstract BaseSpecialService{
   @EJB DelegateService injectedService;
}

请注意,这只是一个 POJO:它没有 @Stateless 或 @Stateful 注释。 这个想法是当我想使用这个服务时,我在另一个 ejb-jar 中用一个具体的 @Stateless Bean class 扩展它。但是我只希望这个用于我需要的服务,其他服务应该作为 POJOS 来处理。

在 weblogic 10 中这工作得很好,但是当移动到 weblogic 12 时,我无法部署该应用程序,因为容器试图在我上面的示例中注入 DelegateService,即使 @EJB 注释不在EJB 但在 POJO 中。我在部署时收到此错误:

[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.

我的解释是,在 java EE 7 中,所有 jar 都会被扫描以获取注释,而在 java EE 5 中,只有在 application.xml 得到扫描。我正在寻找一种方法来阻止应用程序服务器将依赖项注入我的 POJO 并将共享库 jar 视为普通 jar,而不是 ejb-jar。但是我找不到任何东西可以做到这一点。 非常感谢任何帮助。

WebLogic 的 CDI 容器似乎扫描了您的 jar 文件并尝试将 POJOs/EJBs 注入其中。我的建议是禁用 CDI 扫描给定的 jar 文件并查看结果。您可以通过添加包含以下内容的名为 beans.xml 的文件并将其放入 jar 文件的 META-INF 文件夹中来执行此操作:

<?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>