WebSphere 7.从另一个应用程序注入EJB [英] WebSphere 7. Inject EJB from another application
问题描述
我正在尝试使用@EJB注释注入EJB:
I am trying to inject an EJB with the @EJB annotation:
- 当我将EJB注入到同一个耳朵中的另一个EJB时它工作正常。
- 当我从同一个
服务器中的另一个耳朵将EJB注入另一个EJB时,我得到一个异常:
在调用
方法sayHello期间,EJB抛出了一个意外的(未声明的)异常。异常数据:javax.ejb.EJBException:注入
失败;嵌套异常是:
com.ibm.ejs.container.EJBNotFoundException:接口
com.mycompany.myapp.ejb.test2的EJB在应用程序myapp1中不存在
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
我正在使用WebSphere 7和EJB 3.0。当我自己进行jndi查找时,它运行正常。如何让容器知道从哪里注入我的远程bean?
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包含以下内容:myapp1.jar(EJB所在的位置)
myapp1.ear contains the following : myapp1.jar (where the EJB is)
myapp1 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.ear contains the following : myapp2.jar (where the EJB is)
myapp2 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";
}
}
推荐答案
指定部署应用程序时的绑定( 1 , 2 ),或包含 META-INF / ibm-ejb-jar-bnd.xml 。它看起来像这样:
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:
<ejb-jar-bnd
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd"
version "1.0">
<session name="HelloEjbImpl1">
<ejb-ref name="com.mycompany.myapp.ejb.test1/helloEjb2"
binding-name="myapp2/myapp2.jar/HelloEjbImpl2#com.mycompany.myapp1.ejb.test1.HelloEjb1"
</session>
</ejb-jar-bnd>
ejb-ref name =...$ c如果您使用
@EJB(name =myrefname)
,可以简化$ c>。如果你的myapp2.jar包含一个带有< interface class =...binding-name =.../> $的类似绑定文件,则绑定名称可以简化c $ c>元素。
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.
这篇关于WebSphere 7.从另一个应用程序注入EJB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!