gpt4 book ai didi

grails - Elastic Beanstalk->使用Grails的RDS连接错误

转载 作者:行者123 更新时间:2023-12-02 14:09:29 26 4
gpt4 key购买 nike

我正在将Grails应用程序部署到Amazon Web Services Elastic Beanstalk并利用RDS。我正在使用Grails,Spring-Security(RDS表)。该应用程序似乎运行正常(已撤回RDS中的登录和数据)。但是,有时我第一次登录时会收到数据库连接错误。第二次(立即)运行正常。我要做的唯一一点不同是尝试对连接字符串,用户名和密码使用Java系统属性来外部化连接属性:

production {
dataSource {
url = System.getProperty("JDBC_CONNECTION_STRING")
driverClassName = "com.mysql.jdbc.Driver"
dbCreate = "validate"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
username = System.getProperty("PARAM1")
password = System.getProperty("PARAM2")
}
}

堆栈跟踪:
Caused by: org.hibernate.TransactionException: JDBC begin failed: 
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:96)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:555)
... 80 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 41,541,715 milliseconds ago. The last packet sent successfully to the server was 41,541,716 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3358)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1970)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:5022)
at org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:371)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:239)
at $Proxy11.setAutoCommit(Unknown Source)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:91)
... 82 more
Caused by: java.net.SocketException: Connection timed out
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3339)
... 95 more

我尝试过的
我将?autoReconnect = true附加到JDBC_CONNECTION_STRING

我已经将它添加到conf / spring / resources.groovy中:
beans = {       
dataSource(BasicDataSource) {

minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}

}

但是,是否在每个环境配置中正确的位置还是可以/应该将其添加到datasource.groovy文件中?另外,如果我添加URL / driverClassName,用户名和密码,以上内容似乎才有效,这意味着它位于多个位置。我尚未确认是否可以解决问题,但是是否有办法将每个环境都放在一个地方?

最佳答案

这应该工作:

production {
dataSource {
url = System.getProperty("JDBC_CONNECTION_STRING")
driverClassName = "com.mysql.jdbc.Driver"
dbCreate = "validate"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
username = System.getProperty("PARAM1")
password = System.getProperty("PARAM2")

//configure DBCP
properties {
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true

validationQuery="SELECT 1"
}
}
}

关于grails - Elastic Beanstalk->使用Grails的RDS连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5348006/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com