【问题标题】:Grails seems to have wrong hibernate dependencyGrails 似乎有错误的休眠依赖
【发布时间】:2014-06-05 07:46:08
【问题描述】:

我正在将我的 Grails 项目从 2.3.5 版升级到 grails 2.4.0。 由于我在生产中有多个应用程序实例,因此我在 git 分支中进行此升级。 因为我必须解决我的应用程序 2.3.5 版本的问题,所以有时我必须切换回该版本。 突然 1.3.5 版本不再运行:

    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': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cache/spi/RegionFactory

当我搜索这个错误时,我发现这部分属于 Hibernate 4.3.5.2 依赖项,它不在 2.3.5 版本的 BuildConfig.groovy 中(但它在 2.4.0 版本中)。 当我运行grails dependency-report 时,它会显示:

    +--- org.grails.plugins:hibernate4:4.3.5.2
|    \--- org.hibernate:hibernate-ehcache:4.3.5.Final
|         \--- org.jboss.logging:jboss-logging-annotations:1.2.0.Beta1
|    \--- org.hibernate:hibernate-validator:5.0.3.Final
|         \--- com.fasterxml:classmate:1.0.0
|    \--- net.sf.ehcache:ehcache-core:2.4.8
|    \--- org.jboss.logging:jboss-logging:3.1.0.GA 
|    \--- org.grails:grails-datastore-gorm-hibernate4:3.1.0.RELEASE
|         \--- org.hibernate.common:hibernate-commons-annotations:4.0.4.Final
|    \--- javax.validation:validation-api:1.1.0.Final

虽然我的 BuildConfig 看起来像这样:

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/${grails.util.Environment.current.name}-${appVersion}.war"
grails.project.dependency.resolver = "maven"

grails.tomcat.nio=true

grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
    // uncomment to disable ehcache
    // excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {
    inherits true // Whether to inherit repository definitions from plugins
    grailsHome()
        mavenLocal()

    grailsPlugins()
    grailsCentral()

    // uncomment the below to enable remote dependency resolution
    // from public Maven repositories
    mavenCentral()
    //mavenRepo "http://snapshots.repository.codehaus.org"
    mavenRepo "http://repository.codehaus.org"
        mavenRepo "https://oss.sonatype.org/content/repositories/snapshots/"

    //for export plugin 1.6
    mavenRepo "http://repo.grails.org/grails/core"
}
dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
    //       runtime 'mysql:mysql-connector-java:5.1.16'

    runtime 'mysql:mysql-connector-java:5.1.21'
    runtime 'com.github.groovy-wslite:groovy-wslite:0.7.1'

    test 'junit:junit:4.11'
    test 'org.hamcrest:hamcrest-all:1.3'
//      runtime "org.jggug.kobo:kobo-commons:0.2"

    //for export plugin 1.6
    compile 'commons-beanutils:commons-beanutils:1.8.3'
}
plugins {
    build ":tomcat:7.0.47"

    // plugins for the compile step
            compile ":scaffolding:2.0.1"
    compile ':cache:1.1.1'
    compile ':mail:1.0.1', {
        excludes 'spring-test'
      }
        compile ":quartz2:2.1.6.2"
        compile ":csv:0.3.1"
        compile ":export:1.6"
//      compile ":jasper:1.2.1"
        compile ":jasper:1.6.1"
        compile ":spring-security-core:1.2.7.3"

        // plugins needed at runtime but not for compilation
    runtime ":hibernate:3.6.10.6" // or ":hibernate4:4.1.11.1"
    runtime ":database-migration:1.3.8"
    runtime ":jquery:1.10.2"
    compile ":jquery-ui:1.10.3"
            runtime ":resources:1.2.1"      
        compile ":events-push:1.0.M7"
//      compile ":ajax-uploader:1.1"

        // Uncomment these (or add new ones) to enable additional resources capabilities
        //runtime ":zipped-resources:1.0"
        //runtime ":cached-resources:1.0"
        //runtime ":yui-minify-resources:0.1.4"

        compile ':cache:1.0.0'
    }
}

如您所见,那里没有 hibernate4:4.3.5.2。 我试图删除我的 .m2 目录,我的 .grails 目录以刷新依赖关系,但没有成功。

但是,在我的笔记本电脑上,我还没有使用 grails 2.4.0 分支,那里一切正常!该依赖关系图仅显示预期的休眠 3.6.10.6 依赖关系。

有人知道这怎么可能吗?

【问题讨论】:

    标签: hibernate grails dependency-management


    【解决方案1】:

    如果您在同一工作区中的 git 分支之间来回切换,则应删除 target 目录并使用与您最近切换到的分支对应的 Grails 版本重建您的代码。仅凭此处提供的信息我不能肯定地说,但取决于可能解决您问题的其他一些因素。

    【讨论】:

      【解决方案2】:

      感谢您的回答 Jeff,但这不是解决方案(我们总是在运行之前 clean)。

      原来问题出在我们自己创建的插件中(上面的 BuildConfig.groovy 中没有显示)。我们还将这些升级到 grails 2.4.0。这添加了 Hibernate4 4.3.5.2。 所以当我切换回我的应用程序的 2.3.5 版本时,我当然也需要切换回 grails 2.3.5 版本的插件!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-08-07
        • 2014-10-26
        • 1970-01-01
        • 2021-09-30
        • 1970-01-01
        • 2015-01-27
        • 1970-01-01
        相关资源
        最近更新 更多