我已经尝试寻找无法实例化InitialContextFactory的解决方案但是他们的答案似乎没有起作用,我已经尝试在JBoss 6 EAP和JBoss 7 AS上运行它,所以看起来我做错了。< / p>
这是我初始化InitialContext的方式:
public static Context getInitialContext( )
throws javax.naming.NamingException {
Properties p = new Properties( );
p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
return new javax.naming.InitialContext(p);
}
这是堆栈跟踪:
javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.SpringCounterWebApp.war:main" from Service Module Loader
org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:664)
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
javax.naming.InitialContext.init(InitialContext.java:223)
javax.naming.InitialContext.<init>(InitialContext.java:197)
com.example.jms.TopicExample.getInitialContext(TopicExample.java:111)
com.example.jms.TopicExample.example(TopicExample.java:32)
com.example.rest.OrderInfoImpl.test(OrderInfoImpl.java:44)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:165)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:92)
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
java.util.concurrent.FutureTask.run(FutureTask.java:138)
org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:209)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:152)
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:114)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:113)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:164)
任何帮助将不胜感激。
答案 0 :(得分:7)
在app服务器中,你应该做的就是new InitialContext()
,没有任何参数。 JNDI由应用服务器为您预先配置了适当的属性。