Tomcat6、DB2 JNDI数据源

Tomcat 6, DB2 JNDI Datasource

我们将 JDNI 数据源 与 DB2 驱动程序结合使用 Tomcat 6。 该应用程序使用 Hibernate 和 Spring Data JPA。

问题是,HotDeployment(使用 RPM)失败。 HotDeployment 后,我们在日志中收到以下错误:

Information: Illegal access: this web application instance has been stopped already. Could not load DB2JccConfiguration.properties. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.

并且应用程序无法启动...

定义在web.xml

<resource-ref>
    <res-ref-name>jdbc/theDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
</resource-ref>

context.xml

<Resource name="jdbc/testDS" auth="Container"    
type="javax.sql.DataSource"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
maxActive="10" minIdle="2" maxIdle="10" maxWait="10000" 
minEvictableIdleTimeMillis="120000"   
timeBetweenEvictionRunsMillis="60000" 
username="xxx" password="xxx"
driverClassName="com.ibm.db2.jcc.DB2Driver"
url="jdbc:db2://xxxx;"
validationQuery="select 1 from sysibm.sysdummy1" />

以及 spring 配置中的 Bean 定义 class:

@Bean
    public DataSource dataSource() throws SQLException {

        DataSource dataSource = null;

        try {
            final JndiDataSourceLookup dsLookup =
            new JndiDataSourceLookup();
            dsLookup.setResourceRef(true);
            dataSource = 
            dsLookup.getDataSource(JNDI_DATASOURCE_BASE_NAME + 
           this.jndiDataSourceLookupName);
        } catch (Exception ex) {
            LOGGER.error(ex.toString());
            throw ex;
        }

        return dataSource;
    }

找到解决方案。我更改为 tomcat7 并将 "org.apache.commons.dbcp.BasicDataSourceFactory" 替换为 tomcat 中的工厂。这样修改后问题就解决了。