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

Tomcat:用于建立到Tomcat 5.5 JNDI树的外部客户端连接的init上下文参数是什么?,tomcat,jndi,Tomcat,Jndi,目前我在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,

目前我在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为默认InitialConText设置所有初始化参数,您可以这样使用它:

// 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的更多信息。我发现了这个在tomcat中使用的有用链接:

这似乎很愚蠢,但事实上,该主题中的方法足够好,值得考虑。 这里的主要思想是:Tomcat服务器有自己的JNDI系统,因此内部web应用必须首先声明要使用的JNDI,然后使用该声明查找远程服务器的对象(Jboss的EJB)

希望对你有帮助


问候,

是的,你说得对。。。您刚才还记得,只有像Glassfish或JBoss这样的EJB服务器向外部客户机公开其JNDI上下文:-(