我在测试应用程序结束时不断收到此错误。
Error Error executing script TestApp: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: Driver:org.postgresql.Driver@997931c returned null for URL:jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000 (Use --stacktrace to see the full trace)
我尝试从2.1.0升级到2.3.7。 run-app工作正常,但测试应用程序一直在破坏。这就是我dataSource.groovy
的样子。
dataSource {
pooled = true
driverClassName = "org.postgresql.Driver"
dialect="org.hibernate.dialect.PostgreSQLDialect"
username = "username"
password = "password"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
// dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:postgresql://localhost/mydb"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}
/*production {
dataSource {
// dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}*/
}
我在依赖项部分下的BuildConfig.groovy
中有这个。
runtime "org.postgresql:postgresql:9.3-1100-jdbc4"
从昨天起就开始了。它曾经在2.1.0中工作。我有大约200多个测试,其中大约50%的测试失败,并且在失败消息结束时是错误。帮助
答案 0 :(得分:0)
尝试切换这个:
dataSource {
pooled = true
driverClassName = "org.postgresql.Driver"
dialect="org.hibernate.dialect.PostgreSQLDialect"
username = "username"
password = "password"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
// dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:postgresql://localhost/mydb"
}
}
test {
dataSource {
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
pooled = true
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}
/*production {
}
*/
}
答案 1 :(得分:0)
test 的网址是一个h2数据库,所以你应该移动:
driverClassName = "org.postgresql.Driver"
dialect="org.hibernate.dialect.PostgreSQLDialect"
到您的开发数据源并添加
driverClassName = "org.h2.Driver"
到您的测试数据源。
答案 2 :(得分:0)
我认为您使用错误的驱动程序来创建h2数据库。试试:
test {
dataSource {
driverClassName = "org.h2.Driver"
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}