当前位置: 首页 > 面试题库 >

Spring-Hibernate应用程序:非法访问:该Web应用程序实例已被停止

印季
2023-03-14
问题内容

我正在以正确的方式处理连接。
1. 我在应用程序中使用“hibernate”连接池。每当我从池中获得连接时,完成事务后,我就会返回池中。
2. 我已监视数据库以检查连接。我将“空闲连接”时间设置为60秒。我发现没有连接对象运行超过60秒。

我仍然经常收到此错误。而且我的Web应用程序正在停止。我每天必须重新启动tomcat。但是,我正在寻找一种永久的解决方案,而无需重新启动tomcat。
谁能解释根本原因?这样我可以解决此问题。

错误日志:

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)

我的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:
我今天又遇到另一个错误。这是日志:

[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

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

@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;
}

如果我做错任何事,请纠正我。


问题答案:

首先,您可能想使用Spring的事务管理器和Hibernate的OpenSessionInViewFilter来管理Session和事务管理。使用这两个,您不必担心管理连接,可以使用其SessionFactory.getCurrentSession()来获取Session。

接下来,您应该将p:testConnectionOnCheckout =“ true”添加到dataSource bean。

您的应用程序正在发生的事情是,一旦连接断开,它就会保持断开状态。这将允许死连接重新启动。



 类似资料:
  • 问题内容: 我遇到这种例外情况,有人可以帮我解决这个问题吗? 我也越来越有相同的异常和。我正在使用Eclipse Indigo SR1和Tomcat V6.0 问题答案: 您可以在重新启动服务器后解决此问题,因为服务器正在缓存较早版本的应用程序。 看这里

  • 我正在尝试使用Spring Boot 2Java10开发,我遇到了一些问题。 该应用程序是一个基于Spring Boot 2的简单Web应用程序。应用程序启动正常,但是当我停止它时,我收到以下警告: 如您所见,我已经将嵌入式Tomcat服务器从版本8切换到9.0.11,以符合Java模块系统。并且应用程序通过选项<代码>-添加-打开java.base/java.lang=ALL-UNNAMED启动

  • 我有一个简单的Spring-Boot应用程序,它只使用AMQP依赖项(仅-例如,没有web依赖项,所以JAR中没有包含应用服务器)。 我只想让应用程序运行并监听队列,并在收到消息时将一些信息记录到DB中--然而,由于没有应用程序服务器,它一启动就会再次关闭(因为什么都没有做)。在监听消息的同时,是否有一种最好的方法来保持应用程序的运行? 代码中没有什么令人惊讶的地方,只是标准的应用程序配置,然后还

  • 我运行我的Android应用程序(基于Java),它可以工作。接下来,我添加到我的应用程序代码: FirebaseFirestore fdb=FirebaseFirestore。getInstance(); 这是我从Android官方网站上得到的代码https://firebase.google.com/docs/firestore/quickstart 应用程序运行,但接下来运行的设备显示消息“

  • 大家好,我正在做一个整合struts2、spring和hibernate的项目,所以当我运行这个项目时,我得到了以下信息: Grave:Erreur lors de la configuration de la classe d'coute de l'application(应用程序侦听器)com。太阳面孔。配置。ConfigureListener java。lang.ClassNotFoundE

  • 现在我得到这个错误....仍然我不知道如何修复....请至少尝试解决这个错误...但是我不能处理前面...!!!!!!!!! 根本原因 java.lang.ClassCastException:java.lang.Integer不能强制转换为java.lang.Long com.os.SpringJPA.Controller.BookController.ListPaging(BookContro