我使用 Weblogic 10.3.6 和 EJB 3.0 制作了一个小例子。我定义了 SimpleService 类,并定义了 weblogic-ejb-jar.xml 文件,以将 SimpleService 类映射到 JNDI 名称。然后将其打包为 EJB 组件并部署到服务器上。部署成功后,我可以看到名为 SimpleServiceBean 的 ejb bean。之后,我使用独立的应用程序通过 InitialContext 和所有必要的环境属性连接到 Weblogic 服务器,尝试查找该 bean。我假设它将在名称为 ejb/SimpleService 下可用,但是却无法找到它。只有在浏览 JNDI 树名称时,我才发现它可用于 SimpleService#ds/base/ejb/SimpleService 名称下。请帮助我理解发生了什么?我应该如何配置 ejb bean 才能使其按照官方 Weblogic 手册中描述的那样在 ejb/SimpleService 下可用?或者这是 EJB bean 的正确 JNDI 名称吗?
我的类和配置如下: ds.base.ejb.SimpleServiceBean:
我的类和配置如下: ds.base.ejb.SimpleServiceBean:
@Stateless(mappedName = "ServiceBean")
@TransactionAttribute(NEVER)
@ExcludeDefaultInterceptors
@Remote(SimpleService.class)
public class SimpleServiceBean implements SimpleService {
...
}
weblogic-ejb-jar.xml
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>ServiceBean</ejb-name>
<jndi-name>ejb/ServiceBean</jndi-name>
<enable-call-by-reference>True</enable-call-by-reference>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
application.xml:
<application>
<display-name>web-app-ear</display-name>
<module>
<ejb>app-ejb-1.0-SNAPSHOT.jar</ejb>
</module>
</application>
然后尝试从独立安装中获取:
InitialContext context = new InitialContext(env);
SimpleService simpleService = (SimpleService)
context.lookup("SimpleService#ds/base/ejb/SimpleService");
assert simpleService != null