Initialcontext in a standalone Java program

前端 未结 6 1500
傲寒
傲寒 2020-12-13 14:38

I\'m using a JNDI for creating tomcat connection pool. It works great in a web application. I believe the InitialContext is provided by the tomcat server.

Co         


        
6条回答
  •  别那么骄傲
    2020-12-13 14:49

    There isn't a way to directly use the Tomcat Context Factory, see here for a little more documentation on the alternatives. But I recommend you try running a registry outside of Tomcat...

    // select the registry context factory for creating a context
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
    
    // specify where that factory is running.
    env.put(Context.PROVIDER_URL, "rmi://server:1099");
    
    // create an initial context that accesses the registry
    Context ctx = new InitialContext(env);
    

    You could change your code in Tomcat to also use this external RegistryContext and then both set(s) would be using the same JNDI provider. This question seems very similar.

提交回复
热议问题