EJB---->改变sessionbean的JNDI名称

本文详细介绍了如何在Jboss中通过@LocalBinding和@RemoteBinding注释自定义SessionBean的Local接口和Remote接口的JNDI名称,并提供了JSP客户端调用EJB的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在Jboss 中要自定义JNDI 名称,可以使用@LocalBinding 和@RemoteBinding 注释,@LocalBinding 注释指定Session Bean 的Local 接口的JNDI 名称,@RemoteBinding 注释指定Session Bean 的Remote 接口的JNDI 名称,变Session Bean 的JNDI 名称
package com.foshanshop.ejb3.impl;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import com.foshanshop.ejb3.LocalOperation;
import com.foshanshop.ejb3.Operation;
import org.jboss.annotation.ejb.LocalBinding;
import org.jboss.annotation.ejb.RemoteBinding;
@Stateless
@Remote ({Operation.class})
@RemoteBinding (jndiBinding="foshanshop/RemoteOperation")
@Local ({LocalOperation.class})
@LocalBinding (jndiBinding="foshanshop/LocalOperation")
public class OperationBean implements Operation, LocalOperation {
private int total = 0;
private int addresult = 0;
public int Add(int a, int b) {
addresult = a + b;
return addresult;
}
public int getResult() {
total += addresult;
return total;
}
}
在JSP 客户端调用上面EJB 的代码片断如下:
InitialContext ctx = new InitialContext(props);
Operation operation = (Operation) ctx.lookup("foshanshop/RemoteOperation");
如果你使用的是weblogic10/Sun Application Server/Glassfish,你可以使用@Stateless.mappedName()设置bean 的全局JNDI 名称,如:
@Stateless(mappedName="OperationBeanRemote")
public class OperationBean implements Operation, LocalOperation {
客户端访问EJB 的代码片断如下:
InitialContext ctx = new InitialContext(props);
Operation operation = (Operation) ctx.lookup("OperationBeanRemote#com.foshanshop.ejb3.Operation");

<Jul 29 17:54:38> <Error> <Deployer> <Failure occurred in the execution of deployment request with ID "7803635478605029" for task "199" on [partition-name: DOMAIN]. Error is: "weblogic.management.DeploymentException: weblogic.application.naming.ReferenceResolutionException: [J2EE:160200]Error resolving ejb-ref "com.lkm.ejb.impl.UserInfoBean/userInfoRemoteEjb" from module "null" of application "LkmNcEjbs". The ejb-ref does not have an ejb-link and the JNDI name of the target bean has not been specified. Attempts to automatically link the ejb-ref to its target bean failed because no EJBs in the application were found to implement the "com.lkm.ejb.service.UserInfoRemoteEjb" interface. Link or map this ejb-ref to its target EJB and ensure the interfaces declared in the ejb-ref are correct." weblogic.management.DeploymentException: weblogic.application.naming.ReferenceResolutionException: [J2EE:160200]Error resolving ejb-ref "com.lkm.ejb.impl.UserInfoBean/userInfoRemoteEjb" from module "null" of application "LkmNcEjbs". The ejb-ref does not have an ejb-link and the JNDI name of the target bean has not been specified. Attempts to automatically link the ejb-ref to its target bean failed because no EJBs in the application were found to implement the "com.lkm.ejb.service.UserInfoRemoteEjb" interface. Link or map this ejb-ref to its target EJB and ensure the interfaces declared in the ejb-ref are correct. at weblogic.application.internal.flow.EnvContextFlow.activate(EnvContextFlow.java:81) at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:752) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45) at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:262) at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:66) Truncated. see log file for complete stacktrace
最新发布
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值