3

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

请问你能帮帮我吗?

4

2 回答 2

6

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

于 2009-04-14T10:31:25.853 回答
1

我发现这个在 Tomcat 中使用的有用链接:从 Tomcat 调用的 Jboss 中的 EJB

这似乎很愚蠢,但实际上该主题中的方法已经足够好,可以考虑。主要思想在这里:Tomcat 服务器有自己的 JNDI 系统,因此内部 Web 应用程序必须首先声明他们想要使用的 JNDI,然后使用该声明来查找远程服务器的对象(Jboss 的 EJB)。

希望对你有帮助,

问候,

于 2009-12-24T10:04:11.590 回答