ICode9

精准搜索请尝试: 精确搜索
首页?>?数据库> 文章详细

与MySql的Tomcat / Hibernate连接失败,出现“通信链接失败”和“权限被拒绝”

2019-09-29 15:15:52??阅读:577??来源: 互联网

标签:spring-jdbc?mysql?hibernate?tomcat?tomcat7


我正在尝试使用Hibernate从tomcat webapp连接到localhost上的MySql(= MariaDB)(让我们称之为A),但是继续获取??通信链接失败(下面附带完整的异常跟踪).

我在另一台机器上有另一个数据库副本(我们称之为B),还使用第三台计算机进行开发(我们称之为C).

1)从C连接到任一DB(A& B)没有问题.
2)在“A”上我没有问题本地连接到DB(运行’mysql -u’命令).我也没有问题在端口3306上执行telnet到A或B.所以我假设两个DB都已启动并且正在运行并可用于连接.

唯一的问题是当我尝试从生产tomcat(在A上运行)连接到A或B db时.我收到错误:

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

从这个错误的类似情况,我看到大多数错误是由于无效的用户/通过凭证或非法IP.我还尝试将ip更改为localhost,127.0.0.1和10.90.41.155(这是该机器的实际ip).没有任何帮助,并且还要记住,连接只能从A上的特定tomcatbet356体育投注官网_bet356看球_bet356如何邮箱验证失败.

我也尝试过以下方法:
1)在catalina启动时添加了“-Djava.net.preferIPv4Stack = true”
2)试图连接到非法地址/端口 – 这改变了(如预期的)从“权限被拒绝”到“无路由到主机”的最终错误.
3)在我的连接字符串中添加了以下内容:“autoReconnect = true& useUnicode = true& createDatabaseIfNotExist = true& characterEncoding = utf-8” – 这导致了相同的错误(“尝试重新连接3次.放弃.”“权限被拒绝(连接失败)”
4)尝试了两个DB网址.对于本地数据库尝试使用localhost,127.0.0.1和实际的ip.在连接字符串中尝试使用和不使用“:3306”

附件是hibernate.cfg文件的完整服务器跟踪异常:





   
   
      org.hibernate.dialect.MySQLDialect
   
   
      com.mysql.jdbc.Driver
   

   
   
      jdbc:mysql://10.90.41.151/boonder
   
   
      root
   
   
   XXXXXXXXXX
   

   
   
   
   



例外情况是:

        type Exception report

        message Handler dispatch failed; nested exception is java.lang.ExceptionInInitializerError

        description The server encountered an internal error that prevented it from fulfilling this request.

        exception

        org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.ExceptionInInitializerError
            org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:982)
            org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
            org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
            org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
            org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
            com.aldondy.boonder.web.controllers.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:27)
            org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        root cause

        java.lang.ExceptionInInitializerError
            com.aldondy.boonder.bl.DataSingleton.(DataSingleton.java:54)
            com.aldondy.boonder.bl.DataSingleton.instance(DataSingleton.java:74)
            com.aldondy.boonder.web.controllers.LoginCtrl.loginInner(LoginCtrl.java:62)
            com.aldondy.boonder.web.controllers.LoginCtrl.login(LoginCtrl.java:41)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            java.lang.reflect.Method.invoke(Method.java:498)
            org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:180)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
            org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
            org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
            org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
            org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
            org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
            com.aldondy.boonder.web.controllers.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:27)
            org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        root cause

        org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
            org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
            org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
            org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
            org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
            org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
            org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
            org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
            org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
            org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
            org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
            com.aldondy.boonder.bl.DataSingleton.(DataSingleton.java:48)
            com.aldondy.boonder.bl.DataSingleton.instance(DataSingleton.java:74)
            com.aldondy.boonder.web.controllers.LoginCtrl.loginInner(LoginCtrl.java:62)
            com.aldondy.boonder.web.controllers.LoginCtrl.login(LoginCtrl.java:41)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            java.lang.reflect.Method.invoke(Method.java:498)
            org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:180)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
            org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
            org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
            org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
            org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
            org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
            com.aldondy.boonder.web.controllers.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:27)
            org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        root cause

        org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
            org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
            org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:101)
            org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:123)
            org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41)
            org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:123)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections.(PooledConnections.java:42)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections.(PooledConnections.java:20)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:161)
    ...
            org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
            org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
            com.aldondy.boonder.bl.DataSingleton.(DataSingleton.java:48)
            com.aldondy.boonder.bl.DataSingleton.instance(DataSingleton.java:74)
            com.aldondy.boonder.web.controllers.LoginCtrl.loginInner(LoginCtrl.java:62)
            com.aldondy.boonder.web.controllers.LoginCtrl.login(LoginCtrl.java:41)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            java.lang.reflect.Method.invoke(Method.java:498)
            org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:180)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
            org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
            org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
            org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
            org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
            org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
            com.aldondy.boonder.web.controllers.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:27)
            org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        root cause

        com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

        The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
            com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:166)
            com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:58)
            com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:853)
            com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:440)
            com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
            com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221)
            org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
            org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)

    ...

    org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
            org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
            org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
            org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
            org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
            org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
            org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
            org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
            com.aldondy.boonder.bl.DataSingleton.(DataSingleton.java:48)
            com.aldondy.boonder.bl.DataSingleton.instance(DataSingleton.java:74)
            com.aldondy.boonder.web.controllers.LoginCtrl.loginInner(LoginCtrl.java:62)
            com.aldondy.boonder.web.controllers.LoginCtrl.login(LoginCtrl.java:41)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            java.lang.reflect.Method.invoke(Method.java:498)
            org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:180)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
            org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
            org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
            org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
            org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
            org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
            com.aldondy.boonder.web.controllers.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:27)
            org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        root cause

        com.mysql.cj.core.exceptions.CJCommunicationsException: Communications link failure

        The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
            sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
            sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)
            com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:93)
            com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:133)
            com.mysql.cj.core.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:149)
            com.mysql.cj.mysqla.io.MysqlaSocketConnection.connect(MysqlaSocketConnection.java:83)
            com.mysql.cj.mysqla.MysqlaSession.connect(MysqlaSession.java:204)
            com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:975)
            com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:843)
            com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:440)
            com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
            com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221)
            org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
            org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:123)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections.(PooledConnections.java:42)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections.(PooledConnections.java:20)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:161)
            org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:109)
            org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:72)
            org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
     org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
            org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
            org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
            org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
            org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
            org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
            org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
            org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
            org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
            com.aldondy.boonder.bl.DataSingleton.(DataSingleton.java:48)
            com.aldondy.boonder.bl.DataSingleton.instance(DataSingleton.java:74)
            com.aldondy.boonder.web.controllers.LoginCtrl.loginInner(LoginCtrl.java:62)
            com.aldondy.boonder.web.controllers.LoginCtrl.login(LoginCtrl.java:41)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            java.lang.reflect.Method.invoke(Method.java:498)
            org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:180)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
            org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
            org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
            org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
            org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
            org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
            com.aldondy.boonder.web.controllers.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:27)
            org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        root cause

        java.net.SocketException: Permission denied (connect failed)
            java.net.PlainSocketImpl.socketConnect(Native Method)
            java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
            java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
            java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
            java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
            java.net.Socket.connect(Socket.java:589)
            com.mysql.cj.core.io.StandardSocketFactory.connect(StandardSocketFactory.java:202)
            com.mysql.cj.mysqla.io.MysqlaSocketConnection.connect(MysqlaSocketConnection.java:57)
            com.mysql.cj.mysqla.MysqlaSession.connect(MysqlaSession.java:204)
            com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:975)
            com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:843)
            com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:440)
            com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
            com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221)
            org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
            org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:123)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections.(PooledConnections.java:42)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections.(PooledConnections.java:20)
            org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:161)
            org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:109)
            org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:72)
            org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
            org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
            org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
            org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
            org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
            org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)

...
    org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
            org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
            org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
            com.aldondy.boonder.bl.DataSingleton.(DataSingleton.java:48)
            com.aldondy.boonder.bl.DataSingleton.instance(DataSingleton.java:74)
            com.aldondy.boonder.web.controllers.LoginCtrl.loginInner(LoginCtrl.java:62)
            com.aldondy.boonder.web.controllers.LoginCtrl.login(LoginCtrl.java:41)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            java.lang.reflect.Method.invoke(Method.java:498)
            org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
            org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
            org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
            org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
            org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
            org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
            com.aldondy.boonder.web.controllers.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:27)
            org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        note The full stack trace of the root cause is available in the Apache Tomcat/7.0.76 logs.

解决方法:

我也跟踪了这个问题.我的症状与你的症状完全相同,我甚至尝试过你尝试过的确切事物.总之,我的问题只发生,因为我在使用SELinux的centos上使用tomcat.

有些人帮我诊断使用以下命令查看安全事件以及为什么某些操作不允许:

sudo ausearch -m avc
sudo grep "tcp_socket" /var/log/audit/audit.log | audit2why // translates log into some human readable reasons why the audit record was generated

我看到的条目如下:

type=AVC msg=audit(1507861264.561:64750): avc: denied { name_connect
} for pid=1326 comm=”java” dest=3306
scontext=system_u:system_r:tomcat_t:s0
tcontext=system_u:object_r:mysqld_port_t:s0 tclass=tcp_socket

Was caused by: Missing type enforcement (TE) allow rule.

You can use audit2allow to generate a loadable module to allow this access.

然后发现这篇关于tomcat和SELinux https://noobient.com/post/165972214381/selinux-woes-with-tomcat-on-centos-74的文章

您可以运行以下命令以查看tomcat是否在tomcat_t安全上下文中运行.

$ps auxZ | grep tomcat

为了真正确定我的错误是否为SELinux,我禁用了SELinux

$sestatus // shows: SELinux status:                 enabled
$sudo vim /etc/selinux/config // set "SELINUX=disabled"
$sudo shutdown -r now
$sestatus // shows: SELinux status:                 disabled

重新启动我的机器,看到tomcat正在进行出站连接.

太好了,现在我至少知道为什么会发生这种情况.当然,如果你需要SELinux,禁用它不是一个解决方案.可能不是解决方案的另一种解决方法是在不经过yum的情况下bet356体育投注官网_bet356看球_bet356如何邮箱验证tomcat. Yum将使用安全上下文bet356体育投注官网_bet356看球_bet356如何邮箱验证tomcat.

我认为现在的行动方针是修改安全上下文或管理tomcat的规则集,以允许它进行传出连接.



标签:spring-jdbc,mysql,hibernate,tomcat,tomcat7

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有