Spring-Hibernate应用程序:非法访问:此Web应用程序实例已被停止 [英] Spring-Hibernate application: Illegal access: this web application instance has been stopped already

查看:905
本文介绍了Spring-Hibernate应用程序:非法访问:此Web应用程序实例已被停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以适当的方式处理连接。

1。我在应用程序中使用'Hibernate'连接池。每当我从池中获得连接时,我将在完成交易后返回池。

2。我已经监视数据库以检查连接。我有一个'空闲连接'时间设置为60秒。我发现没有连接对象运行超过60秒。

我仍然经常遇到这个错误。我的web应用程序正在停止。我必须每天重新启动一次tomcat。但是,我正在寻找一个永久的解决方案,而无需重新启动tomcat。

任何人都可以解释根本原因吗?所以我可以解决这个问题。

错误记录:

 信息:非法访问:此Web应用程序实例已被停止。无法加载com.mchange.v2.c3p0.ComboPooledDataSourceBeanInfo。最终的跟踪堆栈跟踪是由于出于调试目的而抛出的错误以及试图终止导致非法访问的线程而引起的,并且没有功能影响。 
java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1587)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader .java:1546)
在java.lang.Class.forName0(本地方法)$ b $在java.lang.Class.forName(Class.java:264)
...
...
...
在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)$ b $在java.lang.Thread.run(Thread.java :679)

我的hibernate-contect.xml

 <?xml version =1.0encoding =UTF-8?> 
< beans xmlns =http://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xmlns:p =http://www.springframework.org/schema/p
xmlns:tx =http://www.springframework.org/schema/tx
xmlns :context =http://www.springframework.org/schema/context
xsi:schemaLocation =
http://www.springframework.org/schema/beans
http: //www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/ schema / tx / spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context- 3.1.xsd
>

< context:property-placeholder location =/ WEB-INF / spring.properties/>

<! - 启用管理交易的注释风格 - >
< tx:注解驱动的事务管理器=transactionManager/>

<! - 声明用于检索Hibernate会话的Hibernate SessionFactory - >
<! - 请参阅http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.html - >
<! - 请参阅http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/SessionFactory.html - >
<! - 请参阅http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/Session.html - >
< bean id =sessionFactoryclass =org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
p:dataSource-ref =dataSource
p:configLocation =$ {hibernate .config}
p:packagesToScan =com.turborep.turbotracker/>

<! - 声明具有池化功能的数据源 - >
< bean id =dataSourceclass =com.mchange.v2.c3p0.ComboPooledDataSource
destroy-method =close
p:driverClass =$ {app.jdbc。
p:jdbcUrl =$ {app.jdbc.url}
p:user =$ {app.jdbc.username}
p:password =$ {app.jdbc .password}
p:acquireIncrement =5
p:idleConnectionTestPeriod =60
p:maxPoolSize =100
p:maxStatements =50
p:minPoolSize =0/>

<! - 声明一个事务管理器 - >
< bean id =transactionManagerclass =org.springframework.orm.hibernate3.HibernateTransactionManager
p:sessionFactory-ref =sessionFactory/>

< / beans>

Edit1:

今天又有错误。这里是日志:

  [错误] [ajp-bio-8009-exec-4 08:27:13](JDBCExceptionReporter .java:logExceptions:234)无法从底层数据库获取连接! 
[错误] [ajp-bio-8009-exec-4 08:27:13](JDBCExceptionReporter.java:logExceptions:234)无法从底层数据库获取连接!
[错误] [ajp-bio-8009-exec-4 08:27:13](JobServiceImpl.java:getRxmasterID:4399)无法打开连接
org.hibernate.exception.GenericJDBCException:无法打开连接
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
...
...
...
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl .C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 50 more

示例代码我如何使用连接:

  @Resource(name =sessionFactory)
private SessionFactory itsSessionFactory;

@Override
public List< Userloginclone> getAllUserList(){
itsLogger.debug(检索所有用户列表);
Session aSession = null;
列出< Userloginclone> aQueryList = null;
尝试{
Session = itsSessionFactory.openSession();
查询aQuery = aSession.createQuery(FROM Userloginclone);
QueryList = aQuery.list();
} catch(Exception e){
itsLogger.error(e.getMessage(),e);
} finally {
Session.close();
}
返回aQueryList;
}

如果我做错了任何事情,请纠正我。首先,您可能希望使用Spring的事务管理器和Hibernate的OpenSessionInViewFilter来管理会话和事务管理。在这两者中,您不必担心管理连接,可以使用其SessionSactoryFactory.getCurrentSession()获取Session。

接下来,您应该添加p:testConnectionOnCheckout = true到你的dataSource bean。



你的应用程序发生了什么事情,一旦连接死了,它就会死亡。这将允许重新启动死连接。


I am handling the connections in proper way.
1. I am using 'Hibernate' connection pooling in my application. Whenever I get a connection from pool, I am returning back to pool after finishing the transaction.
2. I have monitored the database to check the connections. I have a 'Idle connection' time set to 60 seconds. I found no connection objects are running more than 60 seconds.

Still I am getting this error very often. And my web application is getting stopped. I have to restart tomcat every day once. However, I am looking for a permanent solution without restarting the tomcat.
Can any one explain the root cause? so that I can fix this.

Error Log:

INFO: Illegal access: this web application instance has been stopped already.  Could not load com.mchange.v2.c3p0.ComboPooledDataSourceBeanInfo.  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:1587)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    ...
    ...
    ...
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

My hibernate-contect.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p" 
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.1.xsd
            ">

    <context:property-placeholder location="/WEB-INF/spring.properties" />

    <!-- Enable annotation style of managing transactions -->
    <tx:annotation-driven transaction-manager="transactionManager" />   

    <!-- Declare the Hibernate SessionFactory for retrieving Hibernate sessions -->
    <!-- See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.html -->                           
    <!-- See http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/SessionFactory.html -->
    <!-- See http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/Session.html -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
                 p:dataSource-ref="dataSource"
                 p:configLocation="${hibernate.config}"
                 p:packagesToScan="com.turborep.turbotracker"/>

    <!-- Declare a datasource that has pooling capabilities-->   
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
                destroy-method="close"
                p:driverClass="${app.jdbc.driverClassName}"
                p:jdbcUrl="${app.jdbc.url}"
                p:user="${app.jdbc.username}"
                p:password="${app.jdbc.password}"
                p:acquireIncrement="5"
                p:idleConnectionTestPeriod="60"
                p:maxPoolSize="100"
                p:maxStatements="50"
                p:minPoolSize="0" />

    <!-- Declare a transaction manager-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
                p:sessionFactory-ref="sessionFactory" />

</beans>

Edit1:
I got another error today. Here is the log:

[ERROR] [ajp-bio-8009-exec-4 08:27:13] (JDBCExceptionReporter.java:logExceptions:234) Connections could not be acquired from the underlying database!
[ERROR] [ajp-bio-8009-exec-4 08:27:13] (JDBCExceptionReporter.java:logExceptions:234) Connections could not be acquired from the underlying database!
[ERROR] [ajp-bio-8009-exec-4 08:27:13] (JobServiceImpl.java:getRxmasterID:4399) Cannot open connection
org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
    ...
    ...
    ... 
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
    ... 50 more

Sample code how I am using the connections:

@Resource(name="sessionFactory")
private SessionFactory itsSessionFactory;

@Override
public List<Userloginclone> getAllUserList() {
    itsLogger.debug("Retrieving all user list");
    Session aSession = null;
    List<Userloginclone> aQueryList = null;
    try {
        aSession = itsSessionFactory.openSession();
        Query aQuery = aSession.createQuery("FROM  Userloginclone");
        aQueryList = aQuery.list();
    } catch (Exception e) {
        itsLogger.error(e.getMessage(), e);
    } finally {
        aSession.close();
    }
    return  aQueryList;
}

Please correct me if I am doing any thing wrong.

解决方案

First, you probably want to use Spring's transaction manager and Hibernate's OpenSessionInViewFilter to manage Session's and transaction management. With those two you don't have to worry about managing connections and can grab a Session with itsSessionFactory.getCurrentSession().

Next, you should probably add p:testConnectionOnCheckout="true" to your dataSource bean.

What's happening with your application is that once a connection is dead it stays dead. This will allow a dead connection to be restarted.

这篇关于Spring-Hibernate应用程序:非法访问:此Web应用程序实例已被停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆