BoneCP有时无法从spring属性持有者那里获得配置

时间:2013-02-07 18:30:42

标签: spring bonecp

我一直面对这个问题。我的配置如下

<!-- Load Properties Files -->
<context:property-placeholder location="classpath:*-${environment}.properties" ignore-unresolvable="true"/>

<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
        <property name="driverClass" value="${jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="idleConnectionTestPeriodInMinutes" value="${boneCP.idleConnectionTestPeriodInMinutes}"/>
        <property name="idleMaxAgeInMinutes" value="${boneCP.idleMaxAgeInMinutes}"/>
        <property name="maxConnectionsPerPartition" value="${boneCP.maxConnectionsPerPartition}"/>
        <property name="minConnectionsPerPartition" value="${boneCP.minConnectionsPerPartition}"/>
        <property name="partitionCount" value="${boneCP.partitionCount}"/>
        <property name="acquireIncrement" value="${boneCP.acquireIncrement}"/>
        <property name="statementsCacheSize" value="${boneCP.statementsCacheSize}"/>
        <property name="lazyInit" value="true"/>
        <property name="maxConnectionAgeInSeconds" value="${boneCP.maxConnectionAgeInSeconds}"/>
</bean>

项目在Tomcat 7上运行

在本地计算机上,项目部署时没有错误以及开发服务器。不幸的是,该项目不能再部署在开发服务器上(服务器配置保持不变),而本地机器仍然没问题。每次我在开发服务器上部署项目时,Tomcat都会挂起INFO:部署Web应用程序存档/etc/tomcat/webapps/project.war。但是如果我用实际值配置BoneCP,一切都很好。

有人可以告诉我它有什么问题吗?


原来是lazyInit问题。如果我将其注释掉,服务器可以正常启动。但现在我正面临新问题。当本地机器100%罚款时,Mybatis根本无法访问数据库。然而,不要抛出任何异常。但是当我停止服务器时,我发现了以下异常

INFO: Illegal access: this web application instance has been stopped already.  Could not load com.jolbox.bonecp.PoolUtil.  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.
java.lang.IllegalStateException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1600)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at com.jolbox.bonecp.DefaultConnectionStrategy.getConnectionInternal(DefaultConnectionStrategy.java:94)
    at com.jolbox.bonecp.AbstractConnectionStrategy.getConnection(AbstractConnectionStrategy.java:90)
    at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:540)
    at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:131)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80)
    at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:66)

INFO: Illegal access: this web application instance has been stopped already.  Could not load org.apache.ibatis.reflection.ExceptionUtil.  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.
java.lang.IllegalStateException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1600)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:363)
    at sun.proxy.$Proxy15.selectList(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:195)
    at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:124)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:90)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
    at sun.proxy.$Proxy45.selectByExample(Unknown Source)

1 个答案:

答案 0 :(得分:0)

嗯,它可能是很多东西,但最有可能

  1. 属性不会被您认为的值
  2. 替换
  3. 已超出数据库连接数或主机错误
  4. 1 + 2
  5. 的组合

    对于#1,我会创建一个单独的bean,它需要com.jolbox.bonecp.BoneCPDataSource作为依赖项,并打印出BoneCPDataSource的getter。

    对于#2,我会尽可能多地打开日志记录(请参阅log4j或logback或任何日志框架)。