验证Linux配置Tomcat数据源(DB2)时,数据源的配置如下:
conf\server.xml:
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment type="Java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource 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 driverClassName="com.ibm.db2.jcc.DB2Driver" maxActive="4" maxIdle="2" maxWait="5000" password="123456" type="javax.sql.DataSource" url="jdbc:db2://127.0.0.1:50000/zxdb" username="db2admin"/>
</GlobalNamingResources>
conf\context.xml:
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<ResourceLink global="DefaultDataSource" type="javax.sql.DataSource"/>
</Context>
异常错误信息如下:
Message: 没有找到名称为 ''{0}'' 的数据源.(the datasource with
name 'default' cannot get connection!)
at
com.primeton.common.connection.impl.datasource.ext.UnconfirmedD
ataSource.getDataSource(UnconfirmedDataSource.java:83)
at
com.primeton.common.connection.impl.datasource.ext.UnconfirmedD
ataSource.getConnection(UnconfirmedDataSource.java:124)
将db2jcc.jar、db2jcc_license_cisuz.jar、db2jcc_license_cu.jar、jta.jar(解决java.lang.NoClassDefFoundError: javax/transaction/UserTransaction)
4个jar包,放到Tomcat的common\lib目录下,然后重启服务。