首页 文章

Weblogic下的EJB bean JNDI名称不清楚

提问于
浏览
3

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

我的课程和配置是:

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

2 回答

  • 1

    关于glassfish.org上的全局门户JNDI名称有一个很好的FaQ http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#SessionBeanGlobalJNDINameAssignment最佳做法是不分配jndi名称,而是依赖自EE 5以来定义的名称(例如SimpleService#ds / base / ejb / SimpleService)

    如果将jndi-name配置添加到weblogic-ejb-jar.xml,实际上可以将其作为ejb / ServiceBean使用,但您还必须在ejb-jar.xml中定义它"old school"样式 . 有关weblogic-ejb-jar.xml的更多信息,请访问http://docs.oracle.com/cd/E23943_01/web.1111/e13719/ejb_jar_ref.htm

    关于orcl文档中的dd也有很好的概述 . http://docs.oracle.com/cd/E23943_01/web.1111/e13719/understanding.htm#EJBPG129

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

  • 1

    用这个 .

    @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");
    

    希望能帮助到你 .

相关问题