我在javaee6的教程中到处读到,可以在两台不同的机器上部署EJB模块和WEB模块。然而,我在任何地方都找不到关于如何实现这一点的教程。那么,如何连接这两个服务器,以便WEB应用程序中的组件能够找到我的远程EJB呢?
发布于 2015-02-03 17:06:14
下面是我是如何做到的:
The EJB
@Stateless(name = "beanname", mappedName = "jndiBeanName")
public class TheBean implements TheBeanRemote {
@Override
public String theMethod(String str) {
return " Bean Invoked " + str;
}
}EJB的远程接口,必须放在单独的JAR中,这样它就会出现在EJB存档和webapp存档中。
@Remote
public interface TheBeanRemote {
public String theMethode(String str);
}最终在servlet中的某个位置::
InitialContext ic;
TheBeanRemote br;
try {
String jndiName = TheBeanRemote.class.getName();
ic= new InitialContext();
at =(TheBeanRemote) ic.lookup("jndiBeanName");
return at.theMethod(parameter);
} catch (NamingException ex) {
//
}注意,我将打包在ear归档文件中。
https://stackoverflow.com/questions/24823318
复制相似问题