我想只supprot如下
更多Rerference :JSF Application that uses managed-bean and ejb
遠程和本地接口
@Remote
public interface IPersonEAORemote {
public void show();
}
@Local
public interface IPersonEAOLocal {
public void show();
}
EJB豆
@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
我問這個問題,因爲當我@EJB它拋出NPE在那裏如果我仰望然後正常工作。 – JavaAster