我们将一个上下文文件放在 CATALINA_BASE / conf / localhost / MyApp.xml。
的位置MyApp.XML的内容如下。
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/MyApp">>
<Resource
auth="Container"
driverClassName="oracle.jdbc.OracleDriver"
name="jdbc/MyApp_local"
password="XXXX"
type="javax.sql.DataSource"
url="XXXX"
username="XXX"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
initialSize="10"
maxWait="-1"
maxActive="55"
maxIdle="21"
minIdle="13"
timeBetweenEvictionRunsMillis="34000"
minEvictableIdleTimeMillis="55000"
validationQuery="SELECT 1"
validationInterval="34"
testOnBorrow="true"
removeAbandoned="true"
removeAbandonedTimeout="233"
/>
<Resource
auth="Container"
driverClassName="oracle.jdbc.OracleDriver"
name="jdbc/MyApp_local_du"
password="XXX"
username="XXXX"
type="javax.sql.DataSource"
url="XXX"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
initialSize="5"
maxWait="-1"
maxActive="55"
maxIdle="21"
minIdle="13"
timeBetweenEvictionRunsMillis="34000"
minEvictableIdleTimeMillis="55000"
validationQuery="SELECT 1"
validationInterval="34"
testOnBorrow="true"
removeAbandoned="true"
removeAbandonedTimeout="233"
/>
</Context>
was文件已复制到 CATALINA_BASE / webapps / MyApp.war
启动应用程序时未正确创建数据源,因为我在日志中可以看到以下错误。
... 33 common frames omitted
Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452) ~[tomcat-dbcp.jar:7.0.55]
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371) ~[tomcat-dbcp.jar:7.0.55]
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) ~[tomcat-dbcp.jar:7.0.55]
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70) ~[hibernate-entitymanager-4.2.7.Final.jar:4.2.7.Final]
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final]
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final]
... 38 common frames omitted
我认为应用程序无法正确解析JNDI。奇怪的是我没有在我的本地tomcat中得到这个错误。仅当部署到unix环境时才会出现此问题。知道为什么没有检测到上下文。