无法使用Postgres DB启动Grails 3.3.8应用程序

时间:2018-11-28 07:22:35

标签: hibernate spring-boot gradle grails grails-3.3

我开始将应用程序从Grails 2.5.5迁移到在Postgres DB上运行的Grails 3.3.8,但是在IntelliJ中启动应用程序时出现错误。以下是详细信息:

错误:

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'methodValidationPostProcessor' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Unsatisfied dependency expressed through method 'methodValidationPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastoreServiceRegistry': Cannot resolve reference to bean 'hibernateDatastore' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.hibernate.boot.internal.MetadataBuildingContextRootImpl.<init>(Lorg/hibernate/boot/spi/MetadataBuildingOptions;Lorg/hibernate/boot/spi/ClassLoaderAccess;Lorg/hibernate/boot/spi/InFlightMetadataCollector;)V
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1181)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1075)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:225)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:703)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:84)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:393)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:380)
    at grails.boot.GrailsApp$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
    at com.mhz.tascr.Application.main(Application.groovy:8)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastoreServiceRegistry': Cannot resolve reference to bean 'hibernateDatastore' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError

build.gradle:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://repo.grails.org/grails/core" }
        maven { url "http://repo.grails.org/grails/plugins/" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.14.8"
    }
}

repositories {
    mavenLocal()
    mavenCentral()

    maven { url "https://repo.grails.org/grails/core" }
    maven { url "http://repo.grails.org/grails/plugins/" }
}

dependencies {
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails.plugins:hibernate5"
    compile "org.hibernate:hibernate-core:5.3.6.Final"
    compile "org.hibernate:hibernate-ehcache:5.3.6.Final"

    runtime "postgresql:postgresql:9.0-801.jdbc4" // POSTGRES
}

application.yml:

hibernate:
    cache:
        queries: false
        use_second_level_cache: true
        use_query_cache: false
        region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
dataSource:
    pooled: true
    jmxExport: true
    driverClassName: org.postgresql.Driver
    dialect: org.hibernate.dialect.PostgreSQLDialect
environments:
    development:
        dataSource:
            dbCreate: create-drop
            url: jdbc:postgresql://localhost:5432/dev_test
            username: XXXX
            password: XXXX
            logSql: false

gradle.properties:

grailsVersion=3.3.8
gormVersion=6.1.10.RELEASE
gradleWrapperVersion=3.5

我遵循了grails迁移指南,并给出了正确的依赖关系和Postgres方言。我还在外部库中看到了postgresql-9.0-801.jdbc4.jar,因此无法找出错误原因。

谢谢

2 个答案:

答案 0 :(得分:1)

您使用的jdbc驱动程序来自2010年-使用更新的驱动程序,例如https://mvnrepository.com/artifact/org.postgresql/postgresql/42.2.5

GORM 6.1最多支持Hibernate 5.2-您正在使用Hibernate 5.3。

答案 1 :(得分:1)

按照@erichelgeson的建议,我升级了jdbc驱动程序,但还必须进行其他一些更改,例如添加dict1 = {} def createCarDictionary(datafile): for line in datafile.splitlines(): line = line.replace(',', '') key, value, value2 = map(str.strip, line.split('|')) dict1[key] = [int(value), int(value2)] return dict1 datafile = open('data.txt', 'r').read() createCarDictionary(datafile) print(dict1) 并将org.jadira.usertype:usertype.core:5.0.0.GA更改为region.factory_class才能获得它完全正常工作。

build.gradle:

org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory

application.yml:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://repo.grails.org/grails/core" }
        maven { url "http://repo.grails.org/grails/plugins/" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.14.8"
    }
}

repositories {
    mavenLocal()
    mavenCentral()

    maven { url "https://repo.grails.org/grails/core" }
    maven { url "http://repo.grails.org/grails/plugins/" }
}

dependencies {
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
    compile "org.hibernate:hibernate-ehcache"
    compile "org.jadira.usertype:usertype.core:5.0.0.GA"

    runtime "org.postgresql:postgresql:42.2.5" // POSTGRES
}