WebSphere 7. 从另一个应用程序注入 EJB
我正在尝试使用 @EJB 注释注入 EJB:
- 当我将 EJB 注入同一只耳朵中的另一个 EJB 时,它工作正常。
- 当我从同一耳朵的另一只耳朵将一个 EJB 注入另一个 EJB 时 服务器我得到一个异常:
EJB 在调用期间引发了意外的(未声明的)异常 方法“sayHello”。异常数据:javax.ejb.EJBException:注入 失败;嵌套异常是: com.ibm.ejs.container.EJBNotFoundException:带有接口的 EJB com.mycompany.myapp.ejb.test2 不存在于应用程序 myapp1 中
我正在使用 WebSphere 7 和 EJB 3.0。当我自己进行 jndi 查找时,效果很好。如何让容器知道从哪里注入我的远程 bean?
myapp1.ear 包含以下内容: myapp1.jar (EJB 所在位置)
myapp1 EJB :
package com.mycompany.myapp1.ejb.test1;
@Remote
public interface HelloEjb1 {
public String sayHello();
}
EJB Impl :
package com.mycompany.myapp.ejb.test1;
@Stateless
public class HelloEjbImpl1 implements HelloEjb1 {
@EJB
HelloEjb2 helloEjb2;
@Override
public String sayHello() {
return HelloEjb2.sayHello();
}
}
myapp2.ear 包含以下内容: myapp2.jar (EJB 所在位置)
myapp2 EJB :
package com.mycompany.myapp2.ejb.test2;
@Remote
public interface HelloEjb2 {
public String sayHello();
}
EJB Impl :
package com.mycompany.myapp2.ejb.test2;
@Stateless
public class HelloEjbImpl2 implements HelloEjb2 {
@Override
public String sayHello() {
return "Hello";
}
}
I am trying to inject an EJB with the @EJB annotation:
- when I inject an EJB into another EJB in the same ear it works fine.
- when I inject an EJB into another EJB from another ear in the same
server I get an exception:
EJB threw an unexpected (non-declared) exception during invocation of
method "sayHello". Exception data: javax.ejb.EJBException: Injection
failure; nested exception is:
com.ibm.ejs.container.EJBNotFoundException: EJB with interface
com.mycompany.myapp.ejb.test2 not present in application myapp1
I'm using WebSphere 7 and EJB 3.0. When I'm doing a jndi lookup myself, it works fine. How do I let the container know from where to inject my remote beans?
myapp1.ear contains the following : myapp1.jar (where the EJB is)
myapp1 EJB :
package com.mycompany.myapp1.ejb.test1;
@Remote
public interface HelloEjb1 {
public String sayHello();
}
EJB Impl :
package com.mycompany.myapp.ejb.test1;
@Stateless
public class HelloEjbImpl1 implements HelloEjb1 {
@EJB
HelloEjb2 helloEjb2;
@Override
public String sayHello() {
return HelloEjb2.sayHello();
}
}
myapp2.ear contains the following : myapp2.jar (where the EJB is)
myapp2 EJB :
package com.mycompany.myapp2.ejb.test2;
@Remote
public interface HelloEjb2 {
public String sayHello();
}
EJB Impl :
package com.mycompany.myapp2.ejb.test2;
@Stateless
public class HelloEjbImpl2 implements HelloEjb2 {
@Override
public String sayHello() {
return "Hello";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
部署应用程序时指定绑定 (1, 2 ),或包含 META-INF/ibm-ejb-jar-bnd.xml 在您的客户端 (myapp1) EJB 模块中。它看起来像这样:
如果使用
@EJB(name="myrefname")
,则可以简化ejb-ref name="..."
。如果您的 myapp2.jar 包含带有
元素的类似绑定文件,则可以简化绑定名称。Specify the binding when deploying the application (1, 2), or include a META-INF/ibm-ejb-jar-bnd.xml in your client (myapp1) EJB module. It would look something like this:
The
ejb-ref name="..."
can be simplified if you use@EJB(name="myrefname")
. The binding-name can be simplified if your myapp2.jar includes a similar binding file with an<interface class="..." binding-name="..."/>
element.