我定义了一个 EJB,并试图在另一场战争中使用它:
在ejb-api.jar
:
@Remote
public interface Example {
// ...
}
在ejb-impl.war
(使用ejb-api.jar
):
@Stateless(mappedName = "ExampleEjb")
public class ExampleBean implements Example {
// ...
}
在ejb-user.war
(使用ejb-api.jar
):
@WebServlet("/ejbuser")
public class UserServlet extends HttpServlet {
@Override
public void doGet(...) throws Exception {
Example example = null;
try {
InitialContext context = new InitialContext();
example = (Example)context.lookup("ExampleEjb");
} catch (NamingException e) {
e.printStackTrace();
}
}
}
我部署ejb-impl.war
了ejb-user.war
一个 JBoss AS 7.1 实例。如果我将所有类放在同一个 war 文件中,则可以找到 EJB。但这样,它不是(我得到一个NamingException
)。
此外,如果我添加一个jndi.properties
包含这些内容的文件......
java.naming.factory.initial = org.jboss.naming.remote.client.InitialContextFactory
java.naming.provider.url = remote://localhost:4447
jboss.naming.client.ejb.context = true
java.naming.factory.url.pkgs = org.jboss.ejb.client.naming
...然后我收到这种警告:
16:55:46,268 WARNING [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-7) javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.example.war:main" from Service Module Loader: javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.example.war:main" from Service Module Loader
at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:681) [rt.jar:1.7.0_03]
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) [rt.jar:1.7.0_03]
at javax.naming.InitialContext.init(InitialContext.java:242) [rt.jar:1.7.0_03]
at javax.naming.InitialContext.<init>(InitialContext.java:192) [rt.jar:1.7.0_03]
at com.sun.faces.config.WebConfiguration.processJndiEntries(WebConfiguration.java:687) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.config.WebConfiguration.<init>(WebConfiguration.java:134) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.config.WebConfiguration.getInstance(WebConfiguration.java:194) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:163) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_03]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_03]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_03]
你知道我做错了什么吗?