我的應用程序中包含一個.properties文件,其中包含dataSource屬性。 我成立了一個JNDI引用該數據源使用下面的代碼:使用其他應用程序與Tomcat創建的JNDI數據源
// first I create MyDataSource from the properties found in the .properties file
//then :
Context initContext = new InitialContext();
initContext.createSubcontext("jdbc");
initContext.createSubcontext("jdbc/oracle");
initContext.rebind(jdbc/oracle/myDataSource, MyDataSource);
如果我使用這個應用程序查找,數據源中發現:
Context initContext = new InitialContext();
BasicDataSource dataSource =
(BasicDataSource) initContext.lookup("jdbc/oracle/myDataSource")
//everything works fine and I can use my dataSource to getConnection,
//requests, etc...
現在我想用這dataSource在另一個應用程序中。但是,如果我執行的查找操作與之前相同,則不會找到myDataSource(而在Tomcat中仍然存在以前的應用程序,並且在監聽程序的幫助下啓動jndi綁定)。
如何在第二個應用程序中獲取myDataSource,因爲我無法在server.xml或context.xml文件中使用Tomcat資源(由於不同的原因,我必須使用此.properties文件)?
謝謝
如果你想要它的服務器範圍,它必須在Server.xml文件中設置。 – Zoidberg 2009-12-21 14:57:46
我不認爲由Tomcat中的一個webapp綁定的JNDI資源對其他webapps都是可見的。 – skaffman 2009-12-21 15:01:45
因此,你有一個將在tomcat內部運行的web應用程序,並且你不能使用context.xml或web.xml? – ChadNC 2009-12-21 15:18:48