通信链路故障:Hibernate& Spring应用程序

时间:2014-07-31 09:46:42

标签: java mysql spring hibernate

我在 Stackoverflow 的其他问题中尝试了建议的内容,并在下面进行了连接更改

<bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl" value="jdbc:mysql://ipaddress:3306/ccc?useUnicode=true&amp;characterEncoding=utf-8" />
        <property name="user" value="userName" />
        <property name="password" value="password" />
        <property name="maxPoolSize" value="20" />
        <property name="maxStatements" value="30" />
        <property name="testConnectionOnCheckin" value="true" />
        <property name="idleConnectionTestPeriod" value="300" />
        <property name="maxIdleTimeExcessConnections" value="240" />
        <property name="preferredTestQuery" value="SELECT 1" />


    </bean>

但我的项目仍在投掷

  

SEVERE:执行身份验证的异常   com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:   通信链路故障

     

从服务器成功收到的最后一个数据包是852,106   几毫秒之前。成功发送到服务器的最后一个数据包是   31,248毫秒之前在   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)     在   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)     在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     在java.lang.reflect.Constructor.newInstance(Constructor.java:525)     在com.mysql.jdbc.Util.handleNewInstance(Util.java:409)at   com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1127)     在com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3715)at   com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3604)at at   com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4155)at at   com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)at at   com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)at at   com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)at at   com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)     在   com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2212)     在   org.apache.catalina.realm.JDBCRealm.getPassword(JDBCRealm.java:547)     在   org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:406)     在   org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:353)     在   org.apache.catalina.authenticator.AuthenticatorBase.doLogin(AuthenticatorBase.java:848)     在   org.apache.catalina.authenticator.AuthenticatorBase.login(AuthenticatorBase.java:830)     在org.apache.catalina.connector.Request.login(Request.java:2637)at   org.apache.catalina.connector.RequestFacade.login(RequestFacade.java:1064)     在com.ccc.web.view.LoginBean.login(LoginBean.java:283)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:601)at   org.apache.el.parser.AstValue.invoke(AstValue.java:278)at at   org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)     在   com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)     在   javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)     在   com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)     在   org.primefaces.application.DialogActionListener.processAction(DialogActionListener.java:45)     在javax.faces.component.UICommand.broadcast(UICommand.java:315)at   javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)     在   javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)     在   com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)     在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)at   com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:607)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:314)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)     在   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(Thread.java:722)引起:   java.net.SocketException:软件导致连接中止:recv   在java.net.SocketInputStream.socketRead0(本机方法)处失败   java.net.SocketInputStream.read(SocketInputStream.java:150)at   java.net.SocketInputStream.read(SocketInputStream.java:121)at   com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:112)     在   com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:159)     在   com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:187)     在com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3158)at   com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3615)... 61   更

任何人都可以告诉我解决这个问题的最佳方法是什么?

2 个答案:

答案 0 :(得分:0)

好的,我已经使用hikari

完成了这项工作
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">

        <property name="dataSourceProperties">
            <props>
                <prop key="url">jdbc:mysql://ipaddress:3306/cc?useUnicode=true&amp;characterEncoding=utf-8</prop>
                <prop key="user">username</prop>
                <prop key="password">password</prop>
                <prop key="useUnicode">true</prop>
                <prop key="characterEncoding">utf-8</prop>
                <prop key="cachePrepStmts">true</prop>
                <prop key="prepStmtCacheSize">250</prop>
                <prop key="prepStmtCacheSqlLimit">2048</prop>
                <prop key="useServerPrepStmts">true</prop>
            </props>
        </property>
        <property name="dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" />
    </bean>

    <bean id="DataSource" class="com.zaxxer.hikari.HikariDataSource">
        <constructor-arg ref="hikariConfig" />
    </bean>

答案 1 :(得分:-1)

在我的情况下,

是因为mysql服务器的版本。 spring proyecto已配置了mysql服务器5.7,但在我的计算机中已配置了版本8。