Weblogic下的EJB bean JNDI名称不清楚

Weblogic下的EJB bean JNDI名称不清楚,weblogic,ejb-3.0,jndi,weblogic-10.x,Weblogic,Ejb 3.0,Jndi,Weblogic 10.x,我使用WebLogic10.3.6和EJB3.0制作了一个小示例。定义SimpleService类,定义weblogic-ejb-jar.xml以便将SimpleService类映射到JNDI名称,将其打包为EAR文件中的ejb组件并部署到服务器上。部署成功,我可以看到名为SimpleServiceBean的ejb bean。之后,使用独立应用程序通过InitialContext连接到webloigc服务器,并使用所有必要的环境属性,我尝试查找该bean。我假设它将在名称ejb/SimpleSe

我使用WebLogic10.3.6和EJB3.0制作了一个小示例。定义SimpleService类,定义weblogic-ejb-jar.xml以便将SimpleService类映射到JNDI名称,将其打包为EAR文件中的ejb组件并部署到服务器上。部署成功,我可以看到名为SimpleServiceBean的ejb bean。之后,使用独立应用程序通过InitialContext连接到webloigc服务器,并使用所有必要的环境属性,我尝试查找该bean。我假设它将在名称ejb/SimpleService下可用,但在该名称下找不到它,只有在我查看JNDI树名称后,我才发现它在名称SimpleService#ds/base/ejb/SimpleService下可用。帮我了解发生了什么事?我应该如何配置EJBbean,以便它在正式weblogic手册中描述的ejb/SimpleService下可用?或者它是EJB bean的正确JNDI名称

我的类和配置是:

ds.base.ejb.SimpleServiceBean:

@无状态(mappedName=“ServiceBean”)
@事务属性(从不)
@ExcludeDefaultInterceptors
@远程(SimpleService.class)
公共类SimpleServiceBean实现SimpleService{
...
}
weblogic ejb jar.xml


服务豆
ejb/ServiceBean
真的
application.xml:


web应用程序ear
app-ejb-1.0-SNAPSHOT.jar
然后尝试从单机版获取:

InitialContext上下文=新的InitialContext(env);
SimpleService SimpleService=(SimpleService)
查找(“SimpleService#ds/base/ejb/SimpleService”);
断言simpleService!=无效的

glassfish.org上有一个关于全球门户JNDI名称的常见问题解答 最好的做法是不分配jndi名称,而是依赖自EE 5以来定义的名称(例如SimpleService#ds/base/ejb/SimpleService)

如果将jndi名称配置添加到weblogic-ejb-jar.xml中,实际上可以将其作为ejb/ServiceBean使用,但还必须在ejb-jar.xml中定义为“老式”样式。更多关于weblogic-ejb-jar.xml的信息可以找到

orcl文档中也有关于dd的良好概述。

假设您正在使用10.3.x服务器版本…

使用此选项

@Stateless(mappedName="UserFacade")
public class UserFacadeImpl {

//......
}


Properties p=new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://localhost:7001");
InitialContext ctx=new InitialContext(p);
userFacade=(UserFacade)ctx.lookup("UserFacade#com.webservices.facade.UserFacade");
希望能有帮助