【问题标题】:EJB 3.0 lookup in Weblogic 10.3.0Weblogic 10.3.0 中的 EJB 3.0 查找
【发布时间】:2011-06-10 10:48:41
【问题描述】:

1:我们的应用程序运行在Weblogic Application Server,版本10.3.0

2:在我们的系统中,我们需要部署一个符合 EJB 3.0 规范的 EJB。

请在下面找到我们 UAT 环境的示例代码:

/*The remote interface*/

package com.serverside.ejb.session;
import javax.ejb.Remote;

@Remote
public interface ASimpleSessionBeanRemote { 

 public void printThis(String print);

}


/*The bean class*/

package com.serverside.ejb.session;

import javax.ejb.Remote;
import javax.ejb.Stateless;

/**
 * Session Bean implementation class ASimpleSessionBean
 */
@Stateless(name="ASimpleSessionBean", **mappedName = "ASimpleSessionEJB"**)
@Remote(ASimpleSessionBeanRemote.class)
public class ASimpleSessionBean implements ASimpleSessionBeanRemote {

    /**
     * Default constructor. 
     */
    public ASimpleSessionBean() {
        // TODO Auto-generated constructor stub
    }

 @Override
 public void printThis(String print) {
  // TODO Auto-generated method stub
  System.out.println("ASimpleSessionBean : "+print); 
 }

}

3:以上文件打包成jar后成功部署到服务器上。

4:根据 EJB 3.0 规范,部署描述符不是强制性的。因此,jar 不包括 ejb-jar.xml 和 weblogic-ejb-jar.xml

5:请在下面找到,根据 Weblogic Application Server 文档的 EJB3.0 注释参考:

Annotation : @Stateless

Package: javax.ejb.Stateless

Attribute : mappedName

Description : 

Specifies the product-specific name to which the stateless session bean should be mapped.
You can also use this attribute to specify the JNDI name of this stateless session bean. WebLogic Server uses the value of the mappedName attribute when creating the bean’s global JNDI name. In particular, the JNDI name will be:
mappedName#name_of_businessInterface
where name_of_businessInterface is the fully qualified name of the business interface of this session bean.
For example, if you specify mappedName="bank" and the fully qualified name of the business interface is com.CheckingAccount, then the JNDI of the business interface is bank#com.CheckingAccount.

6:根据上述规范,部署在我们应用服务器上的示例 EJB 具有如下绑定名称(反映在 jndi 树中):

ASimpleSessionEJB#com.serverside.ejb.session.ASimpleSessionBeanRemote

使用此名称的 jndi 查找成功:

InitialContext.doLookup("ASimpleSessionEJB#com.serverside.ejb.session.ASimpleSesionBeanRemote");

7:现在,我们希望绑定名称是一个简单的字符串,即查找必须是这样的:

InitialContext.doLookup("ASimpleSessionEJB");

8:为了实现第 7 点,我们尝试使用 ejb-jar.xml 和 weblogic-ejb-jar.xml 如下(抱歉,无法弄清楚如何附加/渲染 xml文件):

9:尽管有第 8 点,绑定名称仍然如下:

ASimpleSessionEJB#com.serverside.ejb.session.ASimpleSessionBeanRemote

10:请指导我们参加第 7 点的解决方案和实施。

谢谢!

【问题讨论】:

标签: jakarta-ee ejb-3.0 ejb jndi weblogic-10.x


【解决方案1】:

这是 weblogic-ejb-jar.xml 的示例配置

<wls:weblogic-enterprise-bean>      
     <wls:ejb-name>BasketBean</wls:ejb-name>            
     <wls:jndi-name>BasketBean</wls:jndi-name>
</wls:weblogic-enterprise-bean>

然后你可以像这样进行 jndi 查找: InitialContext.doLookup("BasketBean");

【讨论】:

    【解决方案2】:

    你能以某种方式粘贴你的 weblogic-ejb.xml 吗?至少名称元素。

    您还可以指定运行此查找代码的位置吗? 我希望它在 web 容器中运行,否则你将看不到 weblogic-ejb.xml。 :)

    如果没有任何帮助,您为什么不创建一个属性文件,您可以在其中指定您的密钥和一个长远程名称,然后使用该密钥进行查找?

    干杯。

    JS

    【讨论】:

      【解决方案3】:

      在 weblogic-ejb-jar.xml 中,您应该能够添加带有 jndi-name 部分的 weblogic-enterprise-bean 部分。这在 Weblogic 版本 10.3.1、10.3.3 和 10.3.4 上非常适合我。我在 10.3.0 上遇到了问题。 ejb 似乎部署得很好,并且 jndi 条目在那里,但是当我尝试调用它时,我发现它找不到 bean 类。不确定是什么原因造成的,但希望 jndi-name 部分对您有用。

      祝你好运。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-16
        • 1970-01-01
        • 2011-10-10
        • 2012-09-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多