目前我正在使用这个JBoss,但我也需要一些外部Tomcat:
Properties props = new Properties(); props.put(Context.PROVIDER_URL, "jnp://localhost:1099"); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client"); props.put("j2ee.clientName", "abtest");使用Google搜索我发现了这些,但我无法弄清楚Tomcat的端口配置接受JNDI连接...
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); props.put(Context.PROVIDER_URL, "http://localhost:???");请你能帮助我吗?
Currently I am using this for JBoss, but I need something also for an external Tomcat:
Properties props = new Properties(); props.put(Context.PROVIDER_URL, "jnp://localhost:1099"); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client"); props.put("j2ee.clientName", "abtest");Searching with Google I find this ones, but I am not able to figure out what Tomcat's port configuring to accept JNDI connection...
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); props.put(Context.PROVIDER_URL, "http://localhost:???");Please can You help me?
最满意答案
据我所知,tomcat不支持远程访问其JNDI树,因此只能从tomcat进程访问它。 因此,tomcat为默认的InitialConext设置所有初始化参数,你可以像这样使用它:
// Obtain our environment naming context Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); // Look up our data source DataSource ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB"); // Allocate and use a connection from the pool Connection conn = ds.getConnection(); ... use this connection to access the database ... conn.close();你也可以在这个链接中了解更多关于tomcat的JNDI
As far as I know, tomcat doe not support remote access to its JNDI tree, so you can access it only from the tomcat process. Because of that, The tomcat sets all the initialization params for the default InitialConext, and you can use it like this:
// Obtain our environment naming context Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); // Look up our data source DataSource ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB"); // Allocate and use a connection from the pool Connection conn = ds.getConnection(); ... use this connection to access the database ... conn.close();You can also learn more of the JNDI in tomcat in this link
更多推荐
发布评论