Hibernate和C3p0池的问题

时间:2015-01-06 22:18:26

标签: java hibernate c3p0

我正在使用hibernate 4.3.0和c3p0池测试Web应用程序,有时在重新加载上下文后我收到此错误:

 INFO: Reloading Context with name [/AppName] is completed
    янв 07, 2015 12:07:14 AM org.apache.catalina.loader.WebappClassLoader loadClass
    INFO: Illegal access: this web application instance has been stopped already.  Could not load com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.  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:1612)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1584)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:44)
        at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:2116)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)

Exception in thread "C3P0PooledConnectionPoolManager[identityToken->1hge136961hmilhm17ylc97|17d425e]-AdminTaskTimer" java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$AsyncTestIdleResourceTask
    at com.mchange.v2.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1584)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:2116)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    ... 5 more

依赖 - 也许hibernate-c3p0 dependecie是enougth?

<dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.2.1</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>4.3.0.Final</version>
</dependency>

休眠设置

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.timeout">3000</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.idle_test_period">300</property>

出现这种错误的原因是什么,热修复它? 与hibernate-c3p0相关的所有依赖都在类路径中。

1 个答案:

答案 0 :(得分:2)

请参阅我添加的评论链接。在重新部署期间卸载类,如果你无法关闭Hibernate的sessionFactory,那么你会得到这些ClassNotFound错误。其中一个答案表明您可以添加自定义ServletContextListener来处理contextDestroyed事件。