【发布时间】: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 点的解决方案和实施。
谢谢!
【问题讨论】:
-
请在以下帖子中查看我的答案:stackoverflow.com/questions/8909573/…
标签: jakarta-ee ejb-3.0 ejb jndi weblogic-10.x