Tomcat:什么是init上下文参数用于建立到Tomcat 5.5 JNDI树的外部客户端连接?(Tomcat: what is the init context params to use for

编程入门 行业动态 更新时间:2024-10-28 16:29:51
Tomcat:什么是init上下文参数用于建立到Tomcat 5.5 JNDI树的外部客户端连接?(Tomcat: what is the init context params to use for making an external client connection to Tomcat 5.5 JNDI tree?)

目前我正在使用这个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

更多推荐

本文发布于:2023-08-02 17:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1378700.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   客户端   参数   JNDI   Tomcat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!