gpt4 book ai didi

Tomcat:用于与 Tomcat 5.5 JNDI 树建立外部客户端连接的初始化上下文参数是什么?

转载 作者:行者123 更新时间:2023-11-28 21:50:46 25 4
gpt4 key购买 nike

目前我正在将它用于 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");

用谷歌搜索我找到了这个,但我无法弄清楚 Tomcat 的端口配置接受 JNDI 连接...

props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.naming.java.javaURLContextFactory");
props.put(Context.PROVIDER_URL, "http://localhost:???");

请问你能帮帮我吗?

最佳答案

据我所知,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();

您还可以在 this link 中了解有关 tomcat 中 JNDI 的更多信息

关于Tomcat:用于与 Tomcat 5.5 JNDI 树建立外部客户端连接的初始化上下文参数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/744389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com