【发布时间】:2014-01-15 05:32:24
【问题描述】:
我正在尝试从使用 JNDI 查找在单独 JVM 上运行的客户端访问远程 EJB3 bean。以下是我的 bean 类:
@Path("/payment/")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@Local({ PaymentWebServiceLocal.class })
@Remote({ PaymentWebServiceRemote.class })
@Stateless(mappedName = "ejb/PaymentWebService")
public class PaymentWebServiceImpl implements PaymentWebServiceLocal,PaymentWebServiceRemote {
private static final Logger logger = Logger.getLogger(PaymentWebServiceImpl.class);
@POST
@Path("/processpayment")
public PaymentResponse processPayment(PaymentRequest request) {
//do something
}
Bean的远程接口如下
@Remote
public interface PaymentWebServiceRemote {
public PaymentResponse processPayment(PaymentRequest request);
}
现在,我使用 JNDI 查找 EJB 以从远程客户端调用 processPayment() 方法,如下所示
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, t3:\\);
Context ctx = new InitialContext(env);
return ctx.lookup("ejb.PaymentWebService#test.webservice.payment.service.PaymentWebServiceRemote");
我不明白的是客户端不知道远程PaymentWebServiceRemote接口。它位于另一个带有 EJB Bean 代码的服务器中。我是否也必须将此接口的副本复制到客户端代码?或者有什么方法可以创建一个带有远程接口的客户端 EJB jar 供客户端在 EJB3 中使用(就像我们在 EJB2 中所做的那样)?
感谢任何帮助。
【问题讨论】: