2014-06-05 12 views
0

我正在將我的Grails項目從版本2.3.5升級到grails 2.4.0。 由於我在生產中有多個應用程序實例,因此我正在git分支中進行此升級。 因爲我必須解決我的應用程序的2.3.5版本中的問題,所以我有時必須切換回該版本。 突然1.3.5版本已經不運行:Grails似乎有錯誤的休眠依賴

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 

當我搜索了這個錯誤,我發現這部分屬於休眠4.3.5.2的依賴,這是不是在BuildConfig.groovy爲2.3.5版本(但它是在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分支,但一切正常!該依賴關係圖僅顯示預期的hibernate 3.6.10.6依賴關係。

有沒有人有任何線索如何這是可能的?

回答

0

感謝您的回答傑夫,但那不是解決方案(我們總是運行之前我們總是clean)。

原來問題出在我們自己創建的插件上(沒有顯示在上面的BuildConfig.groovy中)。我們還將這些升級到了grails 2.4.0。並添加了Hibernate4 4.3.5.2。 因此,當我切換回我的應用程序的2.3.5版本時,我當然也需要切換回grails 2.3.5版本的插件!

1

如果您在同一工作空間中的git分支之間來回切換,應該刪除target目錄並使用與您最近切換到的分支對應的Grails版本重建您的代碼。我不能肯定地只提供這裏提供的信息,但取決於可能解決您的問題的其他因素。