我正在为一家位于印度的公司远程工作,我通过VPN连接到公司网络进行日常工作。
我目前正在使用Grails 2.2.4实现一个项目,该项目位于我的本地系统/计算机上。当连接到我的机器上的本地数据库时,GGTS中的grails项目运行正常。
但是,当我尝试从我项目的开发环境连接到公司网络服务器上托管的数据库时,我遇到了很多连接错误,所有这些都是来自MySQL。
我已将DataSource.groovy配置如下:
dataSource {
pooled = true
driverClassName="com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
username = <username>
password = <password>
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache=true
cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
environments {
development {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://<remoteIP-on company network>:3306/<DB_Name>"
properties{
initialSize="50"
maxActive="100"
minIdle="50"
maxIdle="75"
maxWait="30000"
timeBetweenEvictionRunsMillis="5000"
minEvictableIdleTimeMillis="60000"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="true"
poolPreparedStatements="true"
maxOpenPreparedStatements="100"
validationQuery="SELECT 1 FROM DUAL"
connectionInitSqls="SELECT 1 FROM DUAL"
logAbandoned="true"
}
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://<remoteIP-on company network>:3306/<DB_Name>"
driverClassName="com.mysql.jdbc.Driver"
username = <username>
password = <password>
}
}
production {
dataSource {
dbCreate = "update"
jndiName = "java:comp/env/<JNDIName>"
properties {
maxActive = 50
maxIdle = 25
minIdle = 5
initialSize = 5
minEvictableIdleTimeMillis = 60000
timeBetweenEvictionRunsMillis = 60000
maxWait = 10000
}
}
}
}
我的BuildConfig.groovy设置了以下依赖项:
dependencies {
runtime 'mysql:mysql-connector-java:5.1.40'
}
我将mysql-connector-java-5.1.40-bin.jar文件添加到构建路径和/ lib /文件夹中。
在远程数据库上,通过我机器上的HeidiSQL客户端连接到它,我根据我对相同讨论主题的研究运行了以下查询。
GRANT ALL PRIVILEGES ON <DB_Name>.* TO <username>@'%' IDENTIFIED BY <password>;
FLUSH PRIVILEGES;
当我从命令提示符ping远程服务器时,它也可以正常工作。
ping <Remote Server IP>
Pinging <Remote Server IP> with 32 bytes of data:
Reply from <Remote Server IP>: bytes=32 time=261ms TTL=61
Reply from <Remote Server IP>: bytes=32 time=261ms TTL=61
Reply from <Remote Server IP>: bytes=32 time=257ms TTL=61
Reply from <Remote Server IP>: bytes=32 time=257ms TTL=61
Ping statistics for <Remote Server IP>:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 257ms, Maximum = 261ms, Average = 259ms
现在,当我使用GGTS Run As运行应用程序时 - > Grails Command(run-app)我收到以下错误:
| Error 2016-12-13 18:36:05,400 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (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.)
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (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.)
Line | Method
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (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.)
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (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.)
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (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.)
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (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.)
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by SQLNestedException: Cannot create PoolableConnectionFactory (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.)
->> 1549 | createPoolableConnectionFactory in org.apache.commons.dbcp.BasicDataSource
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1388 | createDataSource in ''
| 1044 | getConnection in ''
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run in java.lang.Thread
Caused by 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.
->> 409 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1118 | createCommunicationsException in com.mysql.jdbc.SQLError
| 343 | <init> . in com.mysql.jdbc.MysqlIO
| 2308 | connectOneTryOnly in com.mysql.jdbc.ConnectionImpl
| 2122 | createNewIO in ''
| 774 | <init> in ''
| 49 | <init> . in com.mysql.jdbc.JDBC4Connection
| 409 | handleNewInstance in com.mysql.jdbc.Util
| 375 | getInstance in com.mysql.jdbc.ConnectionImpl
| 289 | connect in com.mysql.jdbc.NonRegisteringDriver
| 38 | createConnection in org.apache.commons.dbcp.DriverConnectionFactory
| 582 | makeObject in org.apache.commons.dbcp.PoolableConnectionFactory
| 1556 | validateConnectionFactory in org.apache.commons.dbcp.BasicDataSource
| 1545 | createPoolableConnectionFactory in ''
| 1388 | createDataSource in ''
| 1044 | getConnection in ''
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->> 79 | socketConnect in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 339 | doConnect in java.net.AbstractPlainSocketImpl
| 200 | connectToAddress in ''
| 182 | connect in ''
| 172 | connect . in java.net.PlainSocketImpl
| 392 | connect in java.net.SocksSocketImpl
| 579 | connect . in java.net.Socket
| 528 | connect in ''
| 425 | <init> . in ''
| 241 | <init> in ''
| 256 | connect . in com.mysql.jdbc.StandardSocketFactory
| 292 | <init> in com.mysql.jdbc.MysqlIO
| 2308 | connectOneTryOnly in com.mysql.jdbc.ConnectionImpl
| 2122 | createNewIO in ''
| 774 | <init> . in ''
| 49 | <init> in com.mysql.jdbc.JDBC4Connection
| 409 | handleNewInstance in com.mysql.jdbc.Util
| 375 | getInstance in com.mysql.jdbc.ConnectionImpl
| 289 | connect . in com.mysql.jdbc.NonRegisteringDriver
| 38 | createConnection in org.apache.commons.dbcp.DriverConnectionFactory
| 582 | makeObject in org.apache.commons.dbcp.PoolableConnectionFactory
| 1556 | validateConnectionFactory in org.apache.commons.dbcp.BasicDataSource
| 1545 | createPoolableConnectionFactory in ''
| 1388 | createDataSource in ''
| 1044 | getConnection in ''
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run in java.lang.Thread
我已尝试过堆栈溢出和其他网站的所有可用解决方案。 直到现在我一直在关注
上提供的解决方案以及其他一些我无法在此处发布的链接,因为堆栈溢出信誉较少。
我已经完成了与上述链接中提供的所有解决方案完全相同的工作。我仍然有同样的错误。我不确定我错过了什么。甚至不确定这是否是由VPN连接引起的。 请帮我。
答案 0 :(得分:0)
这个问题最终得到了解决。
我在服务器位置./etc/mysql/检查了MySQL conf文件my.cnf。在文件my.cnf中,在[mysqld]部分下,bind-address设置为127.0.0.1。而不是将skip-networking设置为True,默认情况下现在只在localhost上侦听所有mysql ubuntu安装,以避免其他服务器连接到mySQL。
因此我注释掉了这行,在./etc/mysql/文件夹中的my.cnf文件中设置了bind-address = 127.0.0.1并重新启动了mysql,它就像一个魅力!
答案 1 :(得分:0)
有时候,当我们有例如docker,firewell或proxy的层时,这些类型的错误就会来临,很难进行故障排除。我遇到过类似类型的错误。我只是通过将服务器绑定为“ 0.0.0.0”而不是“ localhost”或“ 127.0.0.1”来解决此问题。通过使用这个。 etc / host将使服务器绑定到所有接口。然后我使用'ifconfig'命令检查了localhost的IP。然后将该IP用于我的内部体系结构docker应用程序。多数民众赞成在正常。