使用 Grail 2.4.4 配置 MySQL 数据库(无法创建池的初始连接)
Configuring a MySQL Database using Grail 2.4.4 (Unable to create initial connections of pool)
我真的是 Grails 技术的初学者。我为 Windows 64 位安装了 IDE Groovy/Grails Tool Suite™(GGTS,Grails 2.4.4)。
有关 JDK 和 Grails 的环境路径已正确更新。
我创建了一个名为 'test' 的新项目,添加了一个名为 'test.User' 的新域 class,如下所示:
package test
class User {
Integer id
String firstName
String lastName
static constraints = {
id(blank:false, unique:true)
firstName(blank:false)
lastName(blank:false)
}
}
应用静态脚手架生成相应的 UserController 和与 CRUD 操作关联的视图。
为了检查我的数据模型是否与 H2 数据库一起工作,我对 DataSource.groovy 文件进行了一些更新并且它有效:我添加了一个新用户抛出应用程序,当我 运行在我的 table 用户(使用 grails dbconsole)上的命令 SELECT* 并且我显示了我的新用户条目。所以,到此为止一切正常!
但现在我想使用不同的 JDBC 连接器将我的应用程序连接到另一个 SQL 数据库。我选择了(为了兼容性)在我的 BuildConfig.groovy 文件中提出的那个并取消注释:
runtime mysql:mysql-connector-java:5.1.29
当我 运行 应用程序 'run-app'(默认情况下我认为我们处于开发环境中)时,我注意到依赖项 mysql-connector-java-5.1。 29.jar 已添加到我的 .m2 目录 (C:\Users\my_user_name.m2\repository\mysql\mysql-connector-java.1.29)。所以我认为依赖项已在 Grails 中的一种 MAVEN 文件中正确注册。但是该文件不会出现在 ivy-cache 目录中。正常吗?
我的BuildConfig.groovy文件内容:
grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the test-app JVM, uses the daemon by default
test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the run-app JVM
run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
mavenLocal()
grailsCentral()
mavenCentral()
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
runtime 'mysql:mysql-connector-java:5.1.29'
// runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
//test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
}
plugins {
// plugins for the build system only
build ":tomcat:7.0.55"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.8'
compile ":asset-pipeline:1.9.9"
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
// Uncomment these to enable additional asset-pipeline capabilities
//compile ":sass-asset-pipeline:1.9.0"
//compile ":less-asset-pipeline:1.10.0"
//compile ":coffee-asset-pipeline:1.8.0"
//compile ":handlebars-asset-pipeline:1.3.0.3"
}
}
关于 DataSource.groovy 文件,我替换了有关驱动程序名称的行:
driverClassName = "org.h2.Driver"
来自
driverClassName = "com.mysql.jdbc.Driver"
并且对于每个环境(我知道我只使用开发环境,但这只是为了避免一些错误)我替换了以下几行:
url = "jdbc:h2:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
来自
url = "jdbc:mysql://localhost/test"
我还在默认用户名和密码(作为 root 用户)+ 驱动程序 class 名称下方添加如下(再次针对每个环境):
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
这是我的 DataSource.groovy 文件内容:
dataSource {
pooled = true
jmxExport = true
//driverClassName = "org.h2.Driver"
driverClassName = "com.mysql.jdbc.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
// cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
//url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost/test"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
}
}
test {
dataSource {
dbCreate = "update"
//url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost/test"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
}
}
production {
dataSource {
dbCreate = "update"
//url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost/test"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = true
initialSize = 5
maxActive = 50
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"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
}
}
现在,当我 运行 应用程序时出现以下错误:
ERROR pool.ConnectionPool - Unable to create initial connections of pool.
这是整个错误堆栈:
2016-08-23 16:18:58,040 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
Message: 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
->> 411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1129 | createCommunicationsException in com.mysql.jdbc.SQLError
| 358 | <init> . . . . . . . . . . . in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly . . . . . . in ''
| 2320 | createNewIO in ''
| 834 | <init> . . . . . . . . . . . in ''
| 46 | <init> in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance . . . . . . in com.mysql.jdbc.Util
| 416 | getInstance in com.mysql.jdbc.ConnectionImpl
| 347 | connect . . . . . . . . . . . in com.mysql.jdbc.NonRegisteringDriver
| 266 | run in java.util.concurrent.FutureTask
| 1142 | runWorker . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . . . . . . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->> 79 | socketConnect in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 345 | doConnect in java.net.AbstractPlainSocketImpl
| 206 | connectToAddress . . . . . . in ''
| 188 | connect in ''
| 172 | connect . . . . . . . . . . . in java.net.PlainSocketImpl
| 392 | connect in java.net.SocksSocketImpl
| 589 | connect . . . . . . . . . . . in java.net.Socket
| 538 | connect in ''
| 434 | <init> . . . . . . . . . . . in ''
| 244 | <init> in ''
| 256 | connect . . . . . . . . . . . in com.mysql.jdbc.StandardSocketFactory
| 308 | <init> in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly in ''
| 2320 | createNewIO . . . . . . . . . in ''
| 834 | <init> in ''
| 46 | <init> . . . . . . . . . . . in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance in com.mysql.jdbc.Util
| 416 | getInstance . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
| 347 | connect in com.mysql.jdbc.NonRegisteringDriver
| 266 | run . . . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Error |
2016-08-23 16:19:00,132 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
Message: 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
->> 411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1129 | createCommunicationsException in com.mysql.jdbc.SQLError
| 358 | <init> . . . . . . . . . . . in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly . . . . . . in ''
| 2320 | createNewIO in ''
| 834 | <init> . . . . . . . . . . . in ''
| 46 | <init> in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance . . . . . . in com.mysql.jdbc.Util
| 416 | getInstance in com.mysql.jdbc.ConnectionImpl
| 347 | connect . . . . . . . . . . . in com.mysql.jdbc.NonRegisteringDriver
| 266 | run in java.util.concurrent.FutureTask
| 1142 | runWorker . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . . . . . . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->> 79 | socketConnect in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 345 | doConnect in java.net.AbstractPlainSocketImpl
| 206 | connectToAddress . . . . . . in ''
| 188 | connect in ''
| 172 | connect . . . . . . . . . . . in java.net.PlainSocketImpl
| 392 | connect in java.net.SocksSocketImpl
| 589 | connect . . . . . . . . . . . in java.net.Socket
| 538 | connect in ''
| 434 | <init> . . . . . . . . . . . in ''
| 244 | <init> in ''
| 256 | connect . . . . . . . . . . . in com.mysql.jdbc.StandardSocketFactory
| 308 | <init> in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly in ''
| 2320 | createNewIO . . . . . . . . . in ''
| 834 | <init> in ''
| 46 | <init> . . . . . . . . . . . in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance in com.mysql.jdbc.Util
| 416 | getInstance . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
| 347 | connect in com.mysql.jdbc.NonRegisteringDriver
| 266 | run . . . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Error |
2016-08-23 16:19:02,194 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
Message: 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
->> 411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1129 | createCommunicationsException in com.mysql.jdbc.SQLError
| 358 | <init> . . . . . . . . . . . in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly . . . . . . in ''
| 2320 | createNewIO in ''
| 834 | <init> . . . . . . . . . . . in ''
| 46 | <init> in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance . . . . . . in com.mysql.jdbc.Util
| 416 | getInstance in com.mysql.jdbc.ConnectionImpl
| 347 | connect . . . . . . . . . . . in com.mysql.jdbc.NonRegisteringDriver
| 266 | run in java.util.concurrent.FutureTask
| 1142 | runWorker . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . . . . . . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->> 79 | socketConnect in java.net.DualStackPlainSocketImpl
Error |
2016-08-23 16:19:02,205 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - 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 '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: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
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 '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: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
Line | Method
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | 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 '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: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by 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: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by 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: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | 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.
->> 411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1129 | createCommunicationsException in com.mysql.jdbc.SQLError
| 358 | <init> . in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly in ''
| 2320 | createNewIO in ''
| 834 | <init> . in ''
| 46 | <init> in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance in com.mysql.jdbc.Util
| 416 | getInstance in com.mysql.jdbc.ConnectionImpl
| 347 | connect . in com.mysql.jdbc.NonRegisteringDriver
| 266 | run in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->> 79 | socketConnect in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 345 | doConnect in java.net.AbstractPlainSocketImpl
| 206 | connectToAddress in ''
| 188 | connect in ''
| 172 | connect . in java.net.PlainSocketImpl
| 392 | connect in java.net.SocksSocketImpl
| 589 | connect . in java.net.Socket
| 538 | connect in ''
| 434 | <init> . in ''
| 244 | <init> in ''
| 256 | connect . in com.mysql.jdbc.StandardSocketFactory
| 308 | <init> in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly in ''
| 2320 | createNewIO in ''
| 834 | <init> in ''
| 46 | <init> . in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance in com.mysql.jdbc.Util
| 416 | getInstance in com.mysql.jdbc.ConnectionImpl
| 347 | connect in com.mysql.jdbc.NonRegisteringDriver
| 266 | run . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Error |
Forked Grails VM exited with errorJava HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Grails 似乎找不到驱动程序或类似的东西。但是我们已经看到 JAR 文件已在 .m2 目录中注册。我想知道一件事:这个 JAR 文件是否需要出现在 Grails 依赖项列表中:
整个列表不在图片上,但文件没有出现在列表中。正常吗?该文件是否必须只出现在 .m2 目录中(在常春藤缓存中,这是相同的,该文件不存在)?当我 运行 应用程序时,你认为依赖项可用吗? Grails 是否识别驱动程序抛出 class 路径?
我真的迷路了
非常感谢您的帮助。
但我会说按照以下步骤一一进行:
检查您的机器上是否安装了 mysql 服务器。情况可能是您只安装了 Mysql-client。
在您的 DataSource.groovy 中,我看到很多东西丢失或配置不正确。我注意到的很少是:
a) 缺少方言配置
b) 缺少端口号连接到服务器
以下已更正DataSource.groovy
dataSource {
pooled = true
jmxExport = true
//driverClassName = "org.h2.Driver"
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
// cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
//url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost:3306/test"//you had a missing port here
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
}
}
test {
dataSource {
dbCreate = "update"
//url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost/test"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
}
}
production {
dataSource {
dbCreate = "update"
//url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost/test"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = true
initialSize = 5
maxActive = 50
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"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
}
}
希望对您有所帮助!!如果您在新 DataSource.groovy.
之后遇到任何问题,请告诉我
我真的是 Grails 技术的初学者。我为 Windows 64 位安装了 IDE Groovy/Grails Tool Suite™(GGTS,Grails 2.4.4)。
有关 JDK 和 Grails 的环境路径已正确更新。
我创建了一个名为 'test' 的新项目,添加了一个名为 'test.User' 的新域 class,如下所示:
package test
class User {
Integer id
String firstName
String lastName
static constraints = {
id(blank:false, unique:true)
firstName(blank:false)
lastName(blank:false)
}
}
应用静态脚手架生成相应的 UserController 和与 CRUD 操作关联的视图。
为了检查我的数据模型是否与 H2 数据库一起工作,我对 DataSource.groovy 文件进行了一些更新并且它有效:我添加了一个新用户抛出应用程序,当我 运行在我的 table 用户(使用 grails dbconsole)上的命令 SELECT* 并且我显示了我的新用户条目。所以,到此为止一切正常!
但现在我想使用不同的 JDBC 连接器将我的应用程序连接到另一个 SQL 数据库。我选择了(为了兼容性)在我的 BuildConfig.groovy 文件中提出的那个并取消注释:
runtime mysql:mysql-connector-java:5.1.29
当我 运行 应用程序 'run-app'(默认情况下我认为我们处于开发环境中)时,我注意到依赖项 mysql-connector-java-5.1。 29.jar 已添加到我的 .m2 目录 (C:\Users\my_user_name.m2\repository\mysql\mysql-connector-java.1.29)。所以我认为依赖项已在 Grails 中的一种 MAVEN 文件中正确注册。但是该文件不会出现在 ivy-cache 目录中。正常吗?
我的BuildConfig.groovy文件内容:
grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the test-app JVM, uses the daemon by default
test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the run-app JVM
run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
mavenLocal()
grailsCentral()
mavenCentral()
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
runtime 'mysql:mysql-connector-java:5.1.29'
// runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
//test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
}
plugins {
// plugins for the build system only
build ":tomcat:7.0.55"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.8'
compile ":asset-pipeline:1.9.9"
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
// Uncomment these to enable additional asset-pipeline capabilities
//compile ":sass-asset-pipeline:1.9.0"
//compile ":less-asset-pipeline:1.10.0"
//compile ":coffee-asset-pipeline:1.8.0"
//compile ":handlebars-asset-pipeline:1.3.0.3"
}
}
关于 DataSource.groovy 文件,我替换了有关驱动程序名称的行:
driverClassName = "org.h2.Driver"
来自
driverClassName = "com.mysql.jdbc.Driver"
并且对于每个环境(我知道我只使用开发环境,但这只是为了避免一些错误)我替换了以下几行:
url = "jdbc:h2:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
来自
url = "jdbc:mysql://localhost/test"
我还在默认用户名和密码(作为 root 用户)+ 驱动程序 class 名称下方添加如下(再次针对每个环境):
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
这是我的 DataSource.groovy 文件内容:
dataSource {
pooled = true
jmxExport = true
//driverClassName = "org.h2.Driver"
driverClassName = "com.mysql.jdbc.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
// cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
//url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost/test"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
}
}
test {
dataSource {
dbCreate = "update"
//url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost/test"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
}
}
production {
dataSource {
dbCreate = "update"
//url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost/test"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = true
initialSize = 5
maxActive = 50
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"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
}
}
现在,当我 运行 应用程序时出现以下错误:
ERROR pool.ConnectionPool - Unable to create initial connections of pool.
这是整个错误堆栈:
2016-08-23 16:18:58,040 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
Message: 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
->> 411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1129 | createCommunicationsException in com.mysql.jdbc.SQLError
| 358 | <init> . . . . . . . . . . . in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly . . . . . . in ''
| 2320 | createNewIO in ''
| 834 | <init> . . . . . . . . . . . in ''
| 46 | <init> in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance . . . . . . in com.mysql.jdbc.Util
| 416 | getInstance in com.mysql.jdbc.ConnectionImpl
| 347 | connect . . . . . . . . . . . in com.mysql.jdbc.NonRegisteringDriver
| 266 | run in java.util.concurrent.FutureTask
| 1142 | runWorker . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . . . . . . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->> 79 | socketConnect in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 345 | doConnect in java.net.AbstractPlainSocketImpl
| 206 | connectToAddress . . . . . . in ''
| 188 | connect in ''
| 172 | connect . . . . . . . . . . . in java.net.PlainSocketImpl
| 392 | connect in java.net.SocksSocketImpl
| 589 | connect . . . . . . . . . . . in java.net.Socket
| 538 | connect in ''
| 434 | <init> . . . . . . . . . . . in ''
| 244 | <init> in ''
| 256 | connect . . . . . . . . . . . in com.mysql.jdbc.StandardSocketFactory
| 308 | <init> in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly in ''
| 2320 | createNewIO . . . . . . . . . in ''
| 834 | <init> in ''
| 46 | <init> . . . . . . . . . . . in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance in com.mysql.jdbc.Util
| 416 | getInstance . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
| 347 | connect in com.mysql.jdbc.NonRegisteringDriver
| 266 | run . . . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Error |
2016-08-23 16:19:00,132 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
Message: 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
->> 411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1129 | createCommunicationsException in com.mysql.jdbc.SQLError
| 358 | <init> . . . . . . . . . . . in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly . . . . . . in ''
| 2320 | createNewIO in ''
| 834 | <init> . . . . . . . . . . . in ''
| 46 | <init> in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance . . . . . . in com.mysql.jdbc.Util
| 416 | getInstance in com.mysql.jdbc.ConnectionImpl
| 347 | connect . . . . . . . . . . . in com.mysql.jdbc.NonRegisteringDriver
| 266 | run in java.util.concurrent.FutureTask
| 1142 | runWorker . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . . . . . . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->> 79 | socketConnect in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 345 | doConnect in java.net.AbstractPlainSocketImpl
| 206 | connectToAddress . . . . . . in ''
| 188 | connect in ''
| 172 | connect . . . . . . . . . . . in java.net.PlainSocketImpl
| 392 | connect in java.net.SocksSocketImpl
| 589 | connect . . . . . . . . . . . in java.net.Socket
| 538 | connect in ''
| 434 | <init> . . . . . . . . . . . in ''
| 244 | <init> in ''
| 256 | connect . . . . . . . . . . . in com.mysql.jdbc.StandardSocketFactory
| 308 | <init> in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly in ''
| 2320 | createNewIO . . . . . . . . . in ''
| 834 | <init> in ''
| 46 | <init> . . . . . . . . . . . in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance in com.mysql.jdbc.Util
| 416 | getInstance . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
| 347 | connect in com.mysql.jdbc.NonRegisteringDriver
| 266 | run . . . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Error |
2016-08-23 16:19:02,194 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
Message: 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
->> 411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1129 | createCommunicationsException in com.mysql.jdbc.SQLError
| 358 | <init> . . . . . . . . . . . in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly . . . . . . in ''
| 2320 | createNewIO in ''
| 834 | <init> . . . . . . . . . . . in ''
| 46 | <init> in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance . . . . . . in com.mysql.jdbc.Util
| 416 | getInstance in com.mysql.jdbc.ConnectionImpl
| 347 | connect . . . . . . . . . . . in com.mysql.jdbc.NonRegisteringDriver
| 266 | run in java.util.concurrent.FutureTask
| 1142 | runWorker . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . . . . . . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->> 79 | socketConnect in java.net.DualStackPlainSocketImpl
Error |
2016-08-23 16:19:02,205 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - 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 '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: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
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 '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: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
Line | Method
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | 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 '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: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by 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: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by 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: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | 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.
->> 411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1129 | createCommunicationsException in com.mysql.jdbc.SQLError
| 358 | <init> . in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly in ''
| 2320 | createNewIO in ''
| 834 | <init> . in ''
| 46 | <init> in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance in com.mysql.jdbc.Util
| 416 | getInstance in com.mysql.jdbc.ConnectionImpl
| 347 | connect . in com.mysql.jdbc.NonRegisteringDriver
| 266 | run in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->> 79 | socketConnect in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 345 | doConnect in java.net.AbstractPlainSocketImpl
| 206 | connectToAddress in ''
| 188 | connect in ''
| 172 | connect . in java.net.PlainSocketImpl
| 392 | connect in java.net.SocksSocketImpl
| 589 | connect . in java.net.Socket
| 538 | connect in ''
| 434 | <init> . in ''
| 244 | <init> in ''
| 256 | connect . in com.mysql.jdbc.StandardSocketFactory
| 308 | <init> in com.mysql.jdbc.MysqlIO
| 2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2535 | connectOneTryOnly in ''
| 2320 | createNewIO in ''
| 834 | <init> in ''
| 46 | <init> . in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance in com.mysql.jdbc.Util
| 416 | getInstance in com.mysql.jdbc.ConnectionImpl
| 347 | connect in com.mysql.jdbc.NonRegisteringDriver
| 266 | run . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Error |
Forked Grails VM exited with errorJava HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Grails 似乎找不到驱动程序或类似的东西。但是我们已经看到 JAR 文件已在 .m2 目录中注册。我想知道一件事:这个 JAR 文件是否需要出现在 Grails 依赖项列表中:
整个列表不在图片上,但文件没有出现在列表中。正常吗?该文件是否必须只出现在 .m2 目录中(在常春藤缓存中,这是相同的,该文件不存在)?当我 运行 应用程序时,你认为依赖项可用吗? Grails 是否识别驱动程序抛出 class 路径?
我真的迷路了
非常感谢您的帮助。
但我会说按照以下步骤一一进行:
检查您的机器上是否安装了 mysql 服务器。情况可能是您只安装了 Mysql-client。
在您的 DataSource.groovy 中,我看到很多东西丢失或配置不正确。我注意到的很少是: a) 缺少方言配置 b) 缺少端口号连接到服务器
以下已更正DataSource.groovy
dataSource {
pooled = true
jmxExport = true
//driverClassName = "org.h2.Driver"
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
// cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
//url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost:3306/test"//you had a missing port here
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
}
}
test {
dataSource {
dbCreate = "update"
//url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost/test"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
}
}
production {
dataSource {
dbCreate = "update"
//url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost/test"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = true
initialSize = 5
maxActive = 50
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"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
}
}
希望对您有所帮助!!如果您在新 DataSource.groovy.
之后遇到任何问题,请告诉我