错误 pool.ConnectionPool - 无法创建池的初始连接
Error pool.ConnectionPool - Unable to create initital connections of pool
我正在关注 "Grails 2 - A quick start quide" 一书中名为 TekDays 的 Grails 应用程序开发。当我开始配置 DataSource
时,我遇到了建立数据库连接的问题。我不知道是什么原因,因为我遵循的步骤非常清楚。源代码和错误写在下面。
DataSource.groovy:
dataSource {
pooled = true
jmxExport = true
driverClassName = "org.h2.Driver"
username = "dave"
password = "1234"
}
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:mysql//localhost:3306/tekdays"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000; DB_CLOSE_ON_EXIT=FALSE"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
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
}
}
}
}
构建配置:
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.24'
// 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 ":hibernate:3.6.10.18" // or ":hibernate:3.6.10.18" hibernate4:4.3.6.1
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"
}
}
最后 BootStrap.groovy
import com.tekdays.*
class BootStrap {
def init = { servletContext ->
//if(!TekEvent.get(1)){
new TekUser(fullName: 'John Doe' ,
userName: 'jdoe' ,
password: 't0ps3cr3t' ,
email: 'jdoe@johnsgroovyshop.com' ,
website: 'blog.johnsgroovyshop.com' ,
bio: '''John has been programming for over 40 years. He has worked with every programming language known to man and has settle on Groovy.
In his spare time, John dabbles in astro physics and plays shuffleboard.''').save()
new TekUser(fullName: 'John Deere' ,
userName: 'tractorman' ,
password: 't0ps3cr3t' ,
email: 'john.deere@porkproducers.org' ,
website: 'www.perl.porkproducers.org' ,
bio: '''John is a top notch Perl programmer and a pretty good hand around the farm. If he can't program it he
can plow it!''').save()
def event1 = new TekEvent(name: 'Gateway Code Camp' ,
city: 'Saint Louis, MO' ,
organizer: TekUser.findByFullName('John Doe') ,
venue: 'TBD' ,
startDate: new Date('02/02/2015') ,
endDate: new Date('02/05/2015') ,
description: '''This conference will bring coders from across platforms, languages, and industries
together for an exciting day of tips, tricks, and tech!''').save()
def event2 = new TekEvent(name: 'Perl Before Swine' ,
city: 'Austin, MN' ,
organizer: TekUser.findByFullName('John Deere') ,
venue: 'SPAM Museum' ,
startDate: new Date('06/02/2015') ,
endDate: new Date('10/05/2015') ,
description: '''Join the Perl programmers of the Pork Producers of America as we hone our skills and ham it up a bit.
You can show off your programming chops while trying to win a year's supply of pork chops in our programming
challenge.''').save()
def g1 = TekEvent.findByName('Gateway Code Camp')
g1.addToVolunteers(new TekUser(fullName: 'Sarah Martin' ,
userName: 'sarah' ,
password: '54321' ,
email: 'sarah@matinworld.com' ,
website: 'www.martinworld.com' ,
bio: 'Web designer and Grails afficianado.'))
g1.addToVolunteers(new TekUser(fullName: 'Bill Smith' ,
userName: 'Mr_Smith' ,
password: '12345' ,
email: 'mrbill@email.com' ,
website: 'www.mrbillswebsite.com' ,
bio: 'Software developer, claymation artist.'))
g1.addToRespondents('ben@grailsmail.com')
g1.addToRespondents('zachary@linuxgurus.org')
g1.addToRespondents('solomon@bootstrapwelding.com')
def s1 = new Sponsor(name:'Contegix',
website:'http://www.contegix.com',
description:'Beyond Managed Hosting for your Enterprise').save()
def s2 = new Sponsor(name:'Object Computing Incorporated',
website:'http://www.ociweb.com',
description:'An 00 Software Engineering Company').save()
def sp1 = new Sponsorship(event:g1,
sponsor:s1,
contributionType:'Other',
description:'Cool T-Shirts').save()
def sp2 = new Sponsorship(event:g1,
sponsor:s2,
contributionType:'Venue',
description:'Will be paying for the Moscone').save()
g1.save()
//}
}
def destroy = {
}
}
错误:
Error |
2015-02-02 11:58:40,431 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
Message: Driver:org.h2.Driver@3fdec6a5 returned null for URL:jdbc:mysql//localho
st:3306/tekdays
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
Error |
2015-02-02 11:58:40,533 [localhost-startStop-1] ERROR pool.ConnectionPool - Una
ble to create initial connections of pool.
Message: Driver:org.h2.Driver@68e17b43 returned null for URL:jdbc:mysql//localho
st:3306/tekdays
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
Error |
2015-02-02 11:58:40,642 [localhost-startStop-1] ERROR pool.ConnectionPool - Una
ble to create initial connections of pool.
Message: Driver:org.h2.Driver@317f67a9 returned null for URL:jdbc:mysql//localho
st:3306/tekdays
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
Error |
2015-02-02 11:58:40,665 [localhost-startStop-1] ERROR context.GrailsContextLoade
rListener - Error initializing the application: Error creating bean with name '
transactionManagerPostProcessor': Initialization of bean failed; nested exceptio
n is org.springframework.beans.factory.BeanCreationException: Error creating bea
n with name 'transactionManager': Cannot resolve reference to bean 'sessionFacto
ry' while setting bean property 'sessionFactory'; nested exception is org.spring
framework.beans.factory.BeanCreationException: Error creating bean with name 'se
ssionFactory': Cannot resolve reference to bean 'hibernateProperties' while sett
ing bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernatePr
operties': Cannot resolve reference to bean 'dialectDetector' while setting bean
property 'properties' with key [hibernate.dialect]; nested exception is org.spr
ingframework.beans.factory.BeanCreationException: Error creating bean with name
'dialectDetector': Invocation of init method failed; nested exception is org.spr
ingframework.jdbc.support.MetaDataAccessException: Error while extracting Databa
seMetaData; nested exception is java.sql.SQLException: Driver:org.h2.Driver@317f
67a9 returned null for URL:jdbc:mysql//localhost:3306/tekdays
Message: Error creating bean with name 'transactionManagerPostProcessor': Initia
lization of bean failed; nested exception is org.springframework.beans.factory.B
eanCreationException: Error creating bean with name 'transactionManager': Cannot
resolve reference to bean 'sessionFactory' while setting bean property 'session
Factory'; nested exception is org.springframework.beans.factory.BeanCreationExce
ption: 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: Er
ror creating bean with name 'hibernateProperties': Cannot resolve reference to b
ean 'dialectDetector' while setting bean property 'properties' with key [hiberna
te.dialect]; nested exception is org.springframework.beans.factory.BeanCreationE
xception: Error creating bean with name 'dialectDetector': Invocation of init me
thod failed; nested exception is org.springframework.jdbc.support.MetaDataAccess
Exception: Error while extracting DatabaseMetaData; nested exception is java.sql
.SQLException: Driver:org.h2.Driver@317f67a9 returned null for URL:jdbc:mysql//l
ocalhost:3306/tekdays
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 'transactionManag
er': Cannot resolve reference to bean 'sessionFactory' while setting bean proper
ty '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 'hibernateP
roperties'; nested exception is org.springframework.beans.factory.BeanCreationEx
ception: Error creating bean with name 'hibernateProperties': Cannot resolve ref
erence to bean 'dialectDetector' while setting bean property 'properties' with k
ey [hibernate.dialect]; nested exception is org.springframework.beans.factory.Be
anCreationException: Error creating bean with name 'dialectDetector': Invocation
of init method failed; nested exception is org.springframework.jdbc.support.Met
aDataAccessException: Error while extracting DatabaseMetaData; nested exception
is java.sql.SQLException: Driver:org.h2.Driver@317f67a9 returned null for URL:jd
bc:mysql//localhost:3306/tekdays
->> 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 prope
rty 'hibernateProperties'; nested exception is org.springframework.beans.factory
.BeanCreationException: Error creating bean with name 'hibernateProperties': Can
not resolve reference to bean 'dialectDetector' while setting bean property 'pro
perties' with key [hibernate.dialect]; nested exception is org.springframework.b
eans.factory.BeanCreationException: Error creating bean with name 'dialectDetect
or': Invocation of init method failed; nested exception is org.springframework.j
dbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; ne
sted exception is java.sql.SQLException: Driver:org.h2.Driver@317f67a9 returned
null for URL:jdbc:mysql//localhost:3306/tekdays
->> 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 'hibernatePropert
ies': Cannot resolve reference to bean 'dialectDetector' while setting bean prop
erty 'properties' with key [hibernate.dialect]; nested exception is org.springfr
amework.beans.factory.BeanCreationException: Error creating bean with name 'dial
ectDetector': Invocation of init method failed; nested exception is org.springfr
amework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMet
aData; nested exception is java.sql.SQLException: Driver:org.h2.Driver@317f67a9
returned null for URL:jdbc:mysql//localhost:3306/tekdays
->> 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; neste
d exception is java.sql.SQLException: Driver:org.h2.Driver@317f67a9 returned nul
l for URL:jdbc:mysql//localhost:3306/tekdays
->> 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; nest
ed exception is java.sql.SQLException: Driver:org.h2.Driver@317f67a9 returned nu
ll for URL:jdbc:mysql//localhost:3306/tekdays
->> 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 SQLException: Driver:org.h2.Driver@317f67a9 returned null for URL:jdbc
:mysql//localhost:3306/tekdays
->> 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 error
如果需要其他代码,我会提供。
大家好,我已经找到问题的原因了。
- 首先我需要将 driverClassName 从 "org.h2.Driver" 更改为 "com.mysql.jdbc.Driver"
- 我需要指定正确的数据库用户和密码,开发可以使用root用户。
- 在 url = "jdbc:mysql//localhost:3306/tekdays" 中插入缺失的冒号。正确的应该是这样 url = "jdbc:mysql://localhost:3306/tekdays"
对于以后发现这个问题的人,我在我的 Grails 项目中使用了错误的 Java 版本(1.7 而不是 1.8)后遇到了这个症状。
我正在关注 "Grails 2 - A quick start quide" 一书中名为 TekDays 的 Grails 应用程序开发。当我开始配置 DataSource
时,我遇到了建立数据库连接的问题。我不知道是什么原因,因为我遵循的步骤非常清楚。源代码和错误写在下面。
DataSource.groovy:
dataSource {
pooled = true
jmxExport = true
driverClassName = "org.h2.Driver"
username = "dave"
password = "1234"
}
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:mysql//localhost:3306/tekdays"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000; DB_CLOSE_ON_EXIT=FALSE"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
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
}
}
}
}
构建配置:
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.24'
// 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 ":hibernate:3.6.10.18" // or ":hibernate:3.6.10.18" hibernate4:4.3.6.1
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"
}
}
最后 BootStrap.groovy
import com.tekdays.*
class BootStrap {
def init = { servletContext ->
//if(!TekEvent.get(1)){
new TekUser(fullName: 'John Doe' ,
userName: 'jdoe' ,
password: 't0ps3cr3t' ,
email: 'jdoe@johnsgroovyshop.com' ,
website: 'blog.johnsgroovyshop.com' ,
bio: '''John has been programming for over 40 years. He has worked with every programming language known to man and has settle on Groovy.
In his spare time, John dabbles in astro physics and plays shuffleboard.''').save()
new TekUser(fullName: 'John Deere' ,
userName: 'tractorman' ,
password: 't0ps3cr3t' ,
email: 'john.deere@porkproducers.org' ,
website: 'www.perl.porkproducers.org' ,
bio: '''John is a top notch Perl programmer and a pretty good hand around the farm. If he can't program it he
can plow it!''').save()
def event1 = new TekEvent(name: 'Gateway Code Camp' ,
city: 'Saint Louis, MO' ,
organizer: TekUser.findByFullName('John Doe') ,
venue: 'TBD' ,
startDate: new Date('02/02/2015') ,
endDate: new Date('02/05/2015') ,
description: '''This conference will bring coders from across platforms, languages, and industries
together for an exciting day of tips, tricks, and tech!''').save()
def event2 = new TekEvent(name: 'Perl Before Swine' ,
city: 'Austin, MN' ,
organizer: TekUser.findByFullName('John Deere') ,
venue: 'SPAM Museum' ,
startDate: new Date('06/02/2015') ,
endDate: new Date('10/05/2015') ,
description: '''Join the Perl programmers of the Pork Producers of America as we hone our skills and ham it up a bit.
You can show off your programming chops while trying to win a year's supply of pork chops in our programming
challenge.''').save()
def g1 = TekEvent.findByName('Gateway Code Camp')
g1.addToVolunteers(new TekUser(fullName: 'Sarah Martin' ,
userName: 'sarah' ,
password: '54321' ,
email: 'sarah@matinworld.com' ,
website: 'www.martinworld.com' ,
bio: 'Web designer and Grails afficianado.'))
g1.addToVolunteers(new TekUser(fullName: 'Bill Smith' ,
userName: 'Mr_Smith' ,
password: '12345' ,
email: 'mrbill@email.com' ,
website: 'www.mrbillswebsite.com' ,
bio: 'Software developer, claymation artist.'))
g1.addToRespondents('ben@grailsmail.com')
g1.addToRespondents('zachary@linuxgurus.org')
g1.addToRespondents('solomon@bootstrapwelding.com')
def s1 = new Sponsor(name:'Contegix',
website:'http://www.contegix.com',
description:'Beyond Managed Hosting for your Enterprise').save()
def s2 = new Sponsor(name:'Object Computing Incorporated',
website:'http://www.ociweb.com',
description:'An 00 Software Engineering Company').save()
def sp1 = new Sponsorship(event:g1,
sponsor:s1,
contributionType:'Other',
description:'Cool T-Shirts').save()
def sp2 = new Sponsorship(event:g1,
sponsor:s2,
contributionType:'Venue',
description:'Will be paying for the Moscone').save()
g1.save()
//}
}
def destroy = {
}
}
错误:
Error |
2015-02-02 11:58:40,431 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
Message: Driver:org.h2.Driver@3fdec6a5 returned null for URL:jdbc:mysql//localho
st:3306/tekdays
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
Error |
2015-02-02 11:58:40,533 [localhost-startStop-1] ERROR pool.ConnectionPool - Una
ble to create initial connections of pool.
Message: Driver:org.h2.Driver@68e17b43 returned null for URL:jdbc:mysql//localho
st:3306/tekdays
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
Error |
2015-02-02 11:58:40,642 [localhost-startStop-1] ERROR pool.ConnectionPool - Una
ble to create initial connections of pool.
Message: Driver:org.h2.Driver@317f67a9 returned null for URL:jdbc:mysql//localho
st:3306/tekdays
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
Error |
2015-02-02 11:58:40,665 [localhost-startStop-1] ERROR context.GrailsContextLoade
rListener - Error initializing the application: Error creating bean with name '
transactionManagerPostProcessor': Initialization of bean failed; nested exceptio
n is org.springframework.beans.factory.BeanCreationException: Error creating bea
n with name 'transactionManager': Cannot resolve reference to bean 'sessionFacto
ry' while setting bean property 'sessionFactory'; nested exception is org.spring
framework.beans.factory.BeanCreationException: Error creating bean with name 'se
ssionFactory': Cannot resolve reference to bean 'hibernateProperties' while sett
ing bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernatePr
operties': Cannot resolve reference to bean 'dialectDetector' while setting bean
property 'properties' with key [hibernate.dialect]; nested exception is org.spr
ingframework.beans.factory.BeanCreationException: Error creating bean with name
'dialectDetector': Invocation of init method failed; nested exception is org.spr
ingframework.jdbc.support.MetaDataAccessException: Error while extracting Databa
seMetaData; nested exception is java.sql.SQLException: Driver:org.h2.Driver@317f
67a9 returned null for URL:jdbc:mysql//localhost:3306/tekdays
Message: Error creating bean with name 'transactionManagerPostProcessor': Initia
lization of bean failed; nested exception is org.springframework.beans.factory.B
eanCreationException: Error creating bean with name 'transactionManager': Cannot
resolve reference to bean 'sessionFactory' while setting bean property 'session
Factory'; nested exception is org.springframework.beans.factory.BeanCreationExce
ption: 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: Er
ror creating bean with name 'hibernateProperties': Cannot resolve reference to b
ean 'dialectDetector' while setting bean property 'properties' with key [hiberna
te.dialect]; nested exception is org.springframework.beans.factory.BeanCreationE
xception: Error creating bean with name 'dialectDetector': Invocation of init me
thod failed; nested exception is org.springframework.jdbc.support.MetaDataAccess
Exception: Error while extracting DatabaseMetaData; nested exception is java.sql
.SQLException: Driver:org.h2.Driver@317f67a9 returned null for URL:jdbc:mysql//l
ocalhost:3306/tekdays
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 'transactionManag
er': Cannot resolve reference to bean 'sessionFactory' while setting bean proper
ty '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 'hibernateP
roperties'; nested exception is org.springframework.beans.factory.BeanCreationEx
ception: Error creating bean with name 'hibernateProperties': Cannot resolve ref
erence to bean 'dialectDetector' while setting bean property 'properties' with k
ey [hibernate.dialect]; nested exception is org.springframework.beans.factory.Be
anCreationException: Error creating bean with name 'dialectDetector': Invocation
of init method failed; nested exception is org.springframework.jdbc.support.Met
aDataAccessException: Error while extracting DatabaseMetaData; nested exception
is java.sql.SQLException: Driver:org.h2.Driver@317f67a9 returned null for URL:jd
bc:mysql//localhost:3306/tekdays
->> 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 prope
rty 'hibernateProperties'; nested exception is org.springframework.beans.factory
.BeanCreationException: Error creating bean with name 'hibernateProperties': Can
not resolve reference to bean 'dialectDetector' while setting bean property 'pro
perties' with key [hibernate.dialect]; nested exception is org.springframework.b
eans.factory.BeanCreationException: Error creating bean with name 'dialectDetect
or': Invocation of init method failed; nested exception is org.springframework.j
dbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; ne
sted exception is java.sql.SQLException: Driver:org.h2.Driver@317f67a9 returned
null for URL:jdbc:mysql//localhost:3306/tekdays
->> 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 'hibernatePropert
ies': Cannot resolve reference to bean 'dialectDetector' while setting bean prop
erty 'properties' with key [hibernate.dialect]; nested exception is org.springfr
amework.beans.factory.BeanCreationException: Error creating bean with name 'dial
ectDetector': Invocation of init method failed; nested exception is org.springfr
amework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMet
aData; nested exception is java.sql.SQLException: Driver:org.h2.Driver@317f67a9
returned null for URL:jdbc:mysql//localhost:3306/tekdays
->> 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; neste
d exception is java.sql.SQLException: Driver:org.h2.Driver@317f67a9 returned nul
l for URL:jdbc:mysql//localhost:3306/tekdays
->> 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; nest
ed exception is java.sql.SQLException: Driver:org.h2.Driver@317f67a9 returned nu
ll for URL:jdbc:mysql//localhost:3306/tekdays
->> 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 SQLException: Driver:org.h2.Driver@317f67a9 returned null for URL:jdbc
:mysql//localhost:3306/tekdays
->> 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 error
如果需要其他代码,我会提供。
大家好,我已经找到问题的原因了。
- 首先我需要将 driverClassName 从 "org.h2.Driver" 更改为 "com.mysql.jdbc.Driver"
- 我需要指定正确的数据库用户和密码,开发可以使用root用户。
- 在 url = "jdbc:mysql//localhost:3306/tekdays" 中插入缺失的冒号。正确的应该是这样 url = "jdbc:mysql://localhost:3306/tekdays"
对于以后发现这个问题的人,我在我的 Grails 项目中使用了错误的 Java 版本(1.7 而不是 1.8)后遇到了这个症状。