解决失误导致grails连接mysql错误

本文记录了一次Grails应用程序启动失败的问题排查过程,详细解释了由于数据库配置不当导致的异常原因及解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

"D:\Program Files\Java\jdk1.6.0_14\bin\java" -Xmx256M "-Dgrails.home=D:\Program Files\grails-1.2.0" -Dbase.dir=E:\Progect\java\Intellij\ScheduledTasks "-Dtools.jar=D:\Program Files\Java\jdk1.6.0_14\lib\tools.jar" "-Dgroovy.starter.conf=D:\Program Files\grails-1.2.0/conf/groovy-starter.conf" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=D:\Program Files\JetBrains\IntelliJ IDEA 9.0\bin" -Dfile.encoding=GBK -classpath "D:\Program Files\grails-1.2.0\lib\groovy-all-1.6.7.jar;D:\Program Files\grails-1.2.0\dist\grails-bootstrap-1.2.0.jar;D:\Program Files\JetBrains\IntelliJ IDEA 9.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.groovy.grails.cli.support.GrailsStarter --main org.codehaus.groovy.grails.cli.GrailsScriptRunner --conf "D:\Program Files\grails-1.2.0/conf/groovy-starter.conf" run-app
Welcome to Grails 1.2.0 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: D:\Program Files\grails-1.2.0

Base Directory: E:\Progect\java\Intellij\ScheduledTasks
Resolving dependencies...
Dependencies resolved in 2092ms.
Running script D:\Program Files\grails-1.2.0\scripts\RunApp.groovy
Environment set to development
  [groovyc] Compiling 1 source file to E:\Progect\java\Intellij\ScheduledTasks\target\classes
   [delete] Deleting directory I:\Users\Jeck\.grails\1.2.0\projects\ScheduledTasks\tomcat
Running Grails application..
2010-01-22 09:30:15,597 [main] ERROR context.ContextLoader  - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': 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 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
 at grails.web.container.EmbeddableServer$start.call(Unknown Source)
 at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
 at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
 at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:287)
 at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
 at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
 at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
 at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
 at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
 at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
 at RunApp$_run_closure1.doCall(RunApp.groovy:33)
 at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
 at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
 at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
 at gant.Gant.withBuildListeners(Gant.groovy:344)
 at gant.Gant.this$2$withBuildListeners(Gant.groovy)
 at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
 at gant.Gant.dispatch(Gant.groovy:334)
 at gant.Gant.this$2$dispatch(Gant.groovy)
 at gant.Gant.invokeMethod(Gant.groovy)
 at gant.Gant.processTargets(Gant.groovy:495)
 at gant.Gant.processTargets(Gant.groovy:480)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
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 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
 at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
 ... 24 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
 at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
 at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)
 at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
 at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
 at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
 at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
 at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
 at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
 at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
 at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
 ... 25 more
Caused by: java.net.ConnectException: Connection refused: connect
 at java.net.PlainSocketImpl.socketConnect(Native Method)
 at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
 at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
 at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
 at java.net.Socket.connect(Socket.java:519)
 at java.net.Socket.connect(Socket.java:469)
 at java.net.Socket.<init>(Socket.java:366)
 at java.net.Socket.<init>(Socket.java:209)
 at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
 at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
 at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2027)
 ... 34 more
2010-01-22 09:30:15,605 [main] ERROR [localhost].[/ScheduledTasks]  - Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': 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 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
 at grails.web.container.EmbeddableServer$start.call(Unknown Source)
 at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
 at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
 at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:287)
 at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
 at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
 at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
 at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
 at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
 at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
 at RunApp$_run_closure1.doCall(RunApp.groovy:33)
 at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
 at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
 at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
 at gant.Gant.withBuildListeners(Gant.groovy:344)
 at gant.Gant.this$2$withBuildListeners(Gant.groovy)
 at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
 at gant.Gant.dispatch(Gant.groovy:334)
 at gant.Gant.this$2$dispatch(Gant.groovy)
 at gant.Gant.invokeMethod(Gant.groovy)
 at gant.Gant.processTargets(Gant.groovy:495)
 at gant.Gant.processTargets(Gant.groovy:480)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
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 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 ... 24 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

Last packet sent to the server was 0 ms ago.)
 at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
 at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
 ... 24 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
 at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
 at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)
 at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
 at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
 at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
 at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
 at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
 at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
 at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
 at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
 ... 25 more
Caused by: java.net.ConnectException: Connection refused: connect
 at java.net.PlainSocketImpl.socketConnect(Native Method)
 at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
 at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
 at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
 at java.net.Socket.connect(Socket.java:519)
 at java.net.Socket.connect(Socket.java:469)
 at java.net.Socket.<init>(Socket.java:366)
 at java.net.Socket.<init>(Socket.java:209)
 at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
 at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
 at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2027)
 ... 34 more
2010-01-22 09:30:15,613 [main] ERROR core.StandardContext  - Error listenerStart
2010-01-22 09:30:15,730 [main] ERROR core.StandardContext  - Context [/ScheduledTasks] startup failed due to previous errors
Server running. Browse to http://localhost:8080/ScheduledTasks

Process finished with exit code 1

 以上是错误的细节部分,引起上述错误的原因是因为在开发模式下,默认的数据库创建模式为create-drop,但是若该成update也不会报错,但是当domain类改变的时候,就汇报上面的错误,原因是domain类与数据库无法对应映射了,解决方法是把update改成create-drop就可以了。

dataSource {
	pooled = true
	driverClassName = "com.mysql.jdbc.Driver"
	username = "root"
	password = "1234"
}
hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
	development {
		dataSource {
			dbCreate = "create-drop" // one of 'create', 'create-drop','update'  &autoReconnect=true&failOverReadOnly=false
			url = "jdbc:mysql://localhost:3306/scheduledtasks?useUnicode=true&characterEncoding=UTF-8"
		}
	}
	test {
		dataSource {
			dbCreate = "update"
			url = "jdbc:hsqldb:mem:testDb"
		}
	}
	production {
		dataSource {
			dbCreate = "update"
			url = "jdbc:hsqldb:file:prodDb;shutdown=true"
		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值