我有Tomcat的GlobalNamingResources ResourceLink甲骨文獲得的DataSource
我已經包含了各種略有不同資源 的使用Tomcat 7
javax.naming.NameNotFoundException: Name [jdbc/weblogin01b] is not bound in this Context. Unable to find [jdbc].
at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
at org.apache.naming.factory.ResourceLinkFactory.getObjectInstance(ResourceLinkFactory.java:92)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at org.apache.naming.NamingContext.lookup(NamingContext.java:841)
at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
在CATALINA_BASE/conf目錄/ server.xml中很難得到一個JDBC DataSource所有的目標是相同的連接希望他們中的一個將是正確的:
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource name="jdbc/weblogin01"
username="weblogin01"
password="xxxxx"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.pool.OracleDataSource"
description="Global Address Database"
url="jdbc:oracle:thin:@10.15.120.29:1522:DGSPC"
maxActive="15"
maxIdle="3" />
<Resource name="jdbc/weblogin01b"
user="weblogin01"
password="xxxxx"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:@10.15.120.29:1522:DGSPC"
maxActive="20"
maxIdle="3"
maxWait="-1" />
<Resource name="jdbc/weblogin01c"
user="weblogin01"
password="xxxxx"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@10.15.120.29:1522:DGSPC"
maxActive="20"
maxIdle="3"
maxWait="-1" />
</GlobalNamingResources>
在META-INF/context.xml的
我有一個ResourceLink每個資源
<Context antiJARLocking="true" path="/testDbAccess">
<ResourceLink name="jdbc/weblogin01"
global="jdbc/weblogin01"
type="javax.sql.DataSource"/>
<ResourceLink name="jdbc/weblogin01b"
global="jdbc/weblogin01b"
type="javax.sql.DataSource"/>
<ResourceLink name="jdbc/weblogin01c"
global="jdbc/weblogin01c"
type="javax.sql.DataSource"/>
</Context>
在web.xml中我毫不相關的JDBC的理解是 的ResourceLink元素就足夠了變化。
在Java代碼中,我試圖得到一個數據源如下:
String dbUser = "weblogin01b";
try {
// Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
// Look up our data source
ds = (DataSource) envCtx.lookup("jdbc/" + dbUser);
if (ds == null) {
logger.log(Level.WARNING,"Null datasource for " + dbUser);
}
}
鑑於上面的例外,它從來沒有得到一個數據源,這是一樣的:
JDBC/weblogin01
JDBC/weblogin01b
jdbc/weblogin01c
我在找Tomcat一場艱苦的鬥爭,任何幫助都將不勝感激。