我正在做一个小型学校项目。我使用wildfly作为服务器,使用eclipse作为IDE。我也在使用WAMP用于mysql。
这是我的代码:
private static ContactManagerRemote lookupRemoteStatelessContactManager() throws NamingException{
ContactManagerRemote bean=null;
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
Context context=null;
context = new InitialContext(jndiProperties);
final String moduleName = "ProjetContactEAR";
final String distinctName = "ProjetContactEJB";
final String beanName = ContactManager.class.getSimpleName();
final String viewClassname = ContactManagerRemote.class.getName();
String jndi = "ejb:" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassname;
System.out.println(jndi);
return (ContactManagerRemote) context.lookup(jndi);
}
在控制台中,我具有正确的ejb路径(使用System.out.println(jndi):ejb:ProjetContactEAR/ProjetContactEJB/ContactManager!modele.ContactManagerRemote
但是我有这个错误:
javax.naming.NoInitialContextException:需要在环境或系统属性或应用程序资源文件中指定类名称:java.naming.factory.initial
我知道到处都有很多关于这个问题的答案,但是我尝试了一切,到目前为止没有任何结果。