据我所知,tomcat不支持对其JNDI树的远程访问,因此您只能从tomcat进程中访问它。因此,tomcat为默认的InitialConext设置了所有初始化参数,您可以像这样使用它:
// Obtain our environment naming contextContext initCtx = new InitialContext();Context envCtx = (Context) initCtx.lookup("java:comp/env");// Look up our data sourceDataSource ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB");// Allocate and use a connection from the poolConnection conn = ds.getConnection();... use this connection to access the database ...conn.close();您还可以在此链接中了解更多关于tomcat的JNDI



