我只想支持如下
更多参考:使用 managed-bean 和 ejb 的 JSF 应用程序
远程和本地接口
@Remote
public interface IPersonEAORemote {
public void show();
}
@Local
public interface IPersonEAOLocal {
public void show();
}
EJB Bean
@Stateless(name = "PersonEAO", mappedName = "PersonEAO")
public class PersonEAOBean implements IPersonEAORemote, IPersonEAOLocal {
/* if you use JPA
@PersistenceContext(name = "EJB_DEMO")
private EntityManager em;
*/
public void show() {
System.out.println("Good Luck!");
}
}
简单客户端
public class Client {
private IPersonEAORemote personEAO;
private void init() {
try {
final Context context = getInitialContext();
personEAO = (IPersonEAORemote)context.lookup("PersonEAO#<your package name>.IPersonEAORemote");
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static Context getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
// WebLogic Server 10.x connection details
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7101");
return new InitialContext(env);
}
public void show() {
personEAO.show());
}
public static void main(String[] args) {
Client client = new Client();
client.init();
client.show();
}
}
ManageBean :假设您使用 JSF,那么您的支持 bean 就在这里;
public class JSFBackingBean {
@EJB
IPersonEAORemote personEAO;
public void show() {
personEAO.show();
}
}
对于 JBoss 5:
Context.INITIAL_CONTEXT_FACTORY ---> org.jnp.interfaces.NamingContextFactory
Context.PROVIDER_URL ---->http://localhost:1099