1

有一个带有最旧 EJB 的遗留代码库,其中所有现有的 EJBS 都在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>
....

这通过通过 JNDI 进行搜索来工作。但是,服务器已升级到支持Java EE 7的Weblogic 12.2。因此,当向远程会话 bean注入新的本地 EJB时,我想只使用注释,而不触及现有的 XML 部署描述符。ABean@EJB

但是,有以下错误:

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.

新的本地无状态 ejb 代码如下:

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

问题:在这种情况下,是否仍然可以使用注释而不是添加新的 EJB ejb-jar.xml

4

1 回答 1

0

我很害怕,您的部署描述符中的这个小标签version="2.1"告诉应用服务器您的应用程序是 Java EE 2.1 应用程序,它将相应地处理它。所有新的规范功能都将不可用。此外,我担心从 Java-EE 2 到 5 的步骤是如此之大,以至于如果不更改代码,您将无法使您的应用程序成为 JavaEE 5+ 应用程序。我的意思是,在 Java EE 5(Home、Remote 等接口)中删除的所有样板代码似乎仍在您的项目中。但我可能错了,我还没那么老,从第 5 版开始使用 JEE。

于 2020-05-08T13:53:38.453 回答