我是Grails新手。在Datasource.groovy中进行一些基本配置后,我的grails应用程序无法启动。我收到以下错误
Error 2015-07-03 15:27:19,014 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
消息:驱动程序:org.h2.Driver@78f95cf6为URL返回null:jdbc:mysql:// localhost:3306 / radb?createDatabaseIfNotExist = true
|错误2015-07-03 15:27:19,854 [localhost-startStop-1]错误context.GrailsContextLoaderListener - 初始化应用程序时出错:创建名为'transactionManagerPostProcessor'的bean时出错:bean的初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'transactionManager'的bean时出错:在设置bean属性'sessionFactory'时无法解析对bean'sessionFactory'的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'sessionFactory'的bean时出错:init方法的调用失败;嵌套异常是java.lang.NullPointerException
数据库 radb 存在。我已经验证了它
我的Datasource.groovy文件供参考,如下所示
dataSource {
pooled = true
jmxExport = true
driverClassName = "org.h2.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 = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost:3306/radb?createDatabaseIfNotExist=true"
username="root"
password="root"
logSql = true
}
}
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
}
}
}
}
答案 0 :(得分:4)
您的driverClassName
错了。使用正确的mysql(在环境中,例如com.mysql.jdbc.Driver
),你需要mysql。现在你有:
default: driver=h2, dialect=mysql;
dev: url=mysql
prod: url=h2
你肯定想要清理它。还要确保,你的司机中有司机。