用spring+struts2+hibernate做了一个项目,一切正常,只是睡一晚上起来再打开就出现以下异常,然后刷新一下就又没事了。什么原因?望大位大虾指点迷津。
exception javax.servlet.ServletException: org.springframework.transaction.CannotCreateTransactionException: 
Could not open Hibernate Session for transaction; 
nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

解决方案 »

  1.   

    关注中 ,你可以发你的配置文件上来看 ~~~
    以前有过将过滤器配置到web.xml最后,
    第一次不能过滤但再刷新就过滤的情况
    你是不是也有类似的情况 配置文件内容放的有问题?
      

  2.   

    这应该与spring的配置有关,可能是过一段时间spring容器就清空了,spring事务配置如下:
    <bean id="txManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
    <tx:method name="*" propagation="REQUIRED" isolation="REPEATABLE_READ"/>
    </tx:attributes>
    </tx:advice>
    <aop:config>
    <aop:pointcut id="txnServices"
    expression="execution(* com.hongxing.shop.service..*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="txnServices" />
    </aop:config>
      

  3.   

    没人会吗?还是需要提供哪些配置啊?
    下面是异常:
    Last packet sent to the server was 0 ms ago.
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
    org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure