1

我在测试应用程序结束时不断收到此错误。

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 工作正常,但 test-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% 失败了,失败消息的结尾是那个错误。帮助?

4

3 回答 3

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 {
        }
     */
  }
于 2014-04-23T07:57:14.230 回答
0

您的测试网址是一个 h2 数据库,因此您应该移动:

driverClassName = "org.postgresql.Driver"
dialect="org.hibernate.dialect.PostgreSQLDialect"

到您的开发数据源并添加

driverClassName = "org.h2.Driver"

到您的测试数据源。

于 2014-04-23T07:57:14.993 回答
0

我认为您为 h2 数据库使用了错误的驱动程序。尝试:

test {
    dataSource {
        driverClassName = "org.h2.Driver"
        dbCreate = "update"
        url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
    }
}
于 2014-04-23T07:57:52.613 回答