0

我已经尝试寻找无法实例化 InitialContextFactory 的解决方案,但是他们的答案似乎不起作用,我已经尝试在 JBoss 6 EAP 和 JBoss 7 AS 上运行它,所以似乎我做错了。

这就是我初始化 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)

任何帮助,将不胜感激。

4

1 回答 1

7

在应用服务器中,您所要做的就是new InitialContext(),无需任何参数。JNDI 由应用服务器为您预先配置了适当的属性。

于 2013-08-21T08:23:34.270 回答