• hibernate重连


    每天早上上班,发现公司的测试服务器都会报如下错误,百思不得骑姐。

    [00:31:55|ERROR|(org.hibernate.transaction.JDBCTransaction)]=[JDBC begin failed]

    com.mysql.jdbc.CommunicationsException: Communications link failure due to under
    lying exception:

    ** BEGIN NESTED EXCEPTION **

    java.net.SocketException
    MESSAGE: Software caused connection abort: socket write error

    STACKTRACE:

    java.net.SocketException: Software caused connection abort: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65
    )
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2637)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1554)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3118)
    at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5215)
    at org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(Delegating
    Connection.java:331)
    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.
    setAutoCommit(PoolingDataSource.java:317)
    at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:
    91)
    at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354
    )
    at com.concerners.dao.ConcernersDAOImp.getDConcernerCount(ConcernersDAOI
    mp.java:58)
    at com.concerners.service.imp.ConcernersServiceImp.getDConcernerCount(Co
    ncernersServiceImp.java:53)
    at com.mobile.serverceInf.imp.MobileServletInterface.doGet(MobileServlet
    Interface.java:1312)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
    alve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
    alve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
    ava:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
    ava:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
    ve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
    a:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
    :861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
    ss(Http11Protocol.java:620)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:48
    9)
    at java.lang.Thread.run(Thread.java:662)


    ** END NESTED EXCEPTION **

    Last packet sent to the server was 1 ms ago.
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2652)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1554)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3118)
    at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5215)
    at org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(Delegating
    Connection.java:331)
    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.
    setAutoCommit(PoolingDataSource.java:317)
    at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:
    91)
    at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354
    )
    at com.concerners.dao.ConcernersDAOImp.getDConcernerCount(ConcernersDAOI
    mp.java:58)
    at com.concerners.service.imp.ConcernersServiceImp.getDConcernerCount(Co
    ncernersServiceImp.java:53)
    at com.mobile.serverceInf.imp.MobileServletInterface.doGet(MobileServlet
    Interface.java:1312)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
    alve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
    alve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
    ava:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
    ava:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
    ve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
    a:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
    :861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
    ss(Http11Protocol.java:620)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:48
    9)
    at java.lang.Thread.run(Thread.java:662)

     后来修改了配置文件解决了此问题。

    applicationContext.xml

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
      <property name="driverClassName" value="com.mysql.jdbc.Driver" />
      <property name="url" value="jdbc:mysql://localhost/db?autoReconnect=true&amp;autoReconnectForPools=true"/>
      <property name="username" value="root"/>
      <property name="password" value="123"/>
      <property name="validationQuery" value="SELECT 1"/>     
       <property name="testOnBorrow" value="true"/>          
     </bean>

     其实我只加

      <property name="validationQuery" value="SELECT 1"/>     
       <property name="testOnBorrow" value="true"/>        

    就能实现自动重连,测试为mysql 。

  • 相关阅读:
    是什么阻止你达成人生的目标?
    安装cocoa pods
    Mac安装mysql
    Mac安装jee开发环境,webservice环境搭建
    Mac使用Github
    从一个app开始学iOS
    Macbook Pro开机黑屏了。
    U盘安装OSX
    数据分析有时候的结果并不令人满意
    vmvare fusion 8
  • 原文地址:https://www.cnblogs.com/hmdrzql/p/4493809.html
Copyright © 2020-2023  润新知