mysql - Grails 应用程序中 MySql 的管道异常

标签 mysql exception grails grails-2.2

我已将 Grails 2.2.1 应用程序部署到远程服务器。几个小时后,当我访问应用程序的主页时,我看到以下异常:

Error 500: Internal Server Error

URI
    /DocGemStudioZoccali/
Class
    java.net.SocketException
Message
    Broken pipe

Trace

    Line | Method
->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

Caused by GroovyPagesException: Error processing GroovyPageView: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
->>  631 | runWorker in /index.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Caused by DataAccessResourceFailureException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
->>  108 | doCall    in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     25 | doCall    in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
|     38 | run . . . in gsp_docGemStudioZoccaliindex_gsp
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run       in java.lang.Thread

Caused by JDBCConnectionException: could not execute query
->>  108 | doCall    in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     25 | doCall    in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
|     38 | run . . . in gsp_docGemStudioZoccaliindex_gsp
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run       in java.lang.Thread

Caused by CommunicationsException: The last packet successfully received from the server was 138,684,859 milliseconds ago.  The last packet sent successfully to the server was 138,684,859 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.
->>  411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1116 | createCommunicationsException in com.mysql.jdbc.SQLError
|   3851 | send . .  in com.mysql.jdbc.MysqlIO
|   2471 | sendCommand in     ''
|   2651 | sqlQueryDirect in     ''
|   2683 | execSQL   in com.mysql.jdbc.ConnectionImpl
|   2144 | executeInternal in com.mysql.jdbc.PreparedStatement
|   2310 | executeQuery in     ''
|     96 | executeQuery in org.apache.commons.dbcp.DelegatingPreparedStatement
|    108 | doCall    in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
|     25 | doCall .  in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
|     38 | run       in gsp_docGemStudioZoccaliindex_gsp
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

Caused by SocketException: Broken pipe
->>  109 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    153 | write     in     ''
|     82 | flushBuffer in java.io.BufferedOutputStream
|    140 | flush     in     ''
|   3832 | send . .  in com.mysql.jdbc.MysqlIO
|   2471 | sendCommand in     ''
|   2651 | sqlQueryDirect in     ''
|   2683 | execSQL   in com.mysql.jdbc.ConnectionImpl
|   2144 | executeInternal in com.mysql.jdbc.PreparedStatement
|   2310 | executeQuery in     ''
|     96 | executeQuery in org.apache.commons.dbcp.DelegatingPreparedStatement
|    108 | doCall    in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
|     25 | doCall .  in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
|     38 | run       in gsp_docGemStudioZoccaliindex_gsp
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

我已经尝试解决在 SO 中的另一个问题中看到的问题,但它对我不起作用。

这是我在配置文件中所做的:

dataSource {
        dbCreate = "update"
        url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8"
        username = "root"
        password = "root"
        //run the evictor every 30 minutes and evict any connections older than 30 minutes.
        minEvictableIdleTimeMillis=1800000
        timeBetweenEvictionRunsMillis=1800000
        numTestsPerEvictionRun=3
        //test the connection while its idle, before borrow and return it
        testOnBorrow=true
        testWhileIdle=true
        testOnReturn=true
        validationQuery="SELECT 1"
    }

请注意,如果我刷新页面,一切正常。有人知道解决这个问题的方法吗?

编辑 1:

我编辑了 /etc 文件夹中的 my.cnf 文件,添加了以下内容:

wait_timeout = 28800
interactive_timeout = 28800

但没有任何变化

编辑 2:

这是我正在使用的实际数据源。断管依旧出现

dataSource {
   dbCreate = "update"
   url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
   username = "root"
   password = "root"
   minIdle = 5
   maxIdle = 25
   maxWait = 10000
   maxAge = 10 * 60000
   timeBetweenEvictionRunsMillis = 5000
   minEvictableIdleTimeMillis = 60000
   validationQuery = "SELECT 1"
   validationQueryTimeout = 3
   validationInterval = 15000
   testOnBorrow = true
   testWhileIdle = true
   testOnReturn = false
   jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
   defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}

编辑 3:

这是 James Kleeh 给出的建议后的堆栈跟踪

2015-12-04 17:41:36,924 [http-bio-8080-exec-63] 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.BeanCreationException: 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:722)
Caused by: 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        ... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        ... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        ... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        ... 3 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        ... 3 more
2015-12-04 17:41:36,931 [http-bio-8080-exec-63] ERROR context.GrailsContextLoader  - Error initializing Grails: 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.BeanCreationException: 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:722)
Caused by: 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        ... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        ... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        ... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        ... 3 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        ... 3 more
Dec 04, 2015 5:41:36 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Dec 04, 2015 5:41:36 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/DocGemStudioTest] startup failed due to previous errors
2015-12-04 17:41:36,955 [http-bio-8080-exec-63] WARN  lifecycle.ShutdownOperations  - Error occurred running shutdown operation: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:722)
Dec 04, 2015 5:41:36 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/DocGemStudioTest] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

编辑 4:

我已经编辑了 properties block ,现在应用程序启动了。我需要检查几个小时后是否发生错误。

 properties{
                 minIdle = 5
                 maxIdle = 25
                 maxWait = 10000

                 timeBetweenEvictionRunsMillis = 5000
                 minEvictableIdleTimeMillis = 60000
                 validationQuery = "SELECT 1"
                 validationQueryTimeout = 3

                 testOnBorrow = true
                 testWhileIdle = true
                 testOnReturn = false

                 defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
        }

最佳答案

所以我相信除了 dbCreateurlusernamepassword 之外的所有内容都需要在属性 block :

dataSource {
    dbCreate = "update"
    url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
    username = "root"
    password = "root"
    properties {
        minIdle = 5
        maxIdle = 25
        maxWait = 10000
        maxAge = 10 * 60000
        timeBetweenEvictionRunsMillis = 5000
        minEvictableIdleTimeMillis = 60000
        validationQuery = "SELECT 1"
        validationQueryTimeout = 3
        validationInterval = 15000
        testOnBorrow = true
        testWhileIdle = true
        testOnReturn = false
        jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
        defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
    }
}

关于mysql - Grails 应用程序中 MySql 的管道异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31677123/

相关文章:

mysql - 如何从MySQL中动态获取列名获取OLD VALUE和NEW VALUE?

mysql - 查找给定集合中包含 id 的所有聚合表条目

mysql - 使用 vagrant 提供简单的 mysql 设置(使用 shell provisioner)

grails - Groovy Grails垂直而不是水平显示列表

grails - 元替换两个不同的测试中的相同方法不起作用?

mysql - 是否存在 utf8_unicode_cs 排序规则?

javascript - 有人可以提供一个使用 jsTestDriver.js 的断言异常的非常简单的完整示例吗

java - map 或flatMap内的RxJava Single.error

c# - 没有成员访问时怎么会出现NullReferenceException呢?

grails - 我试图在grails 2.2.2中运行我的第一个应用程序..但是当我单击debug时,它给了我一个错误..