java - 移动到新的 spring 后无法启动服务器启动 Tomcat 上下文时出错

标签 java spring hibernate grails grails-orm

最近,我不得不将我的项目升级到最新的 Grails、Gradle、Groovy,并且遇到了很多问题。 目前,我在启动 Tomcat 时遇到了这个特殊问题:

2020-06-07 17:23:22.919 ERROR --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'authenticationProcessingFilterDeregistrationBean': Cannot resolve reference to bean 'authenticationProcessingFilter' while setting bean property 'filter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationProcessingFilter': Cannot resolve reference to bean 'authenticationManager' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationManager': Cannot resolve reference to bean 'daoAuthenticationProvider' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoAuthenticationProvider': Cannot resolve reference to bean 'userDetailsService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService': Unsatisfied dependency expressed through method 'setTargetDatastore' parameter 0; 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.NullPointerException: Cannot invoke method call() on null object
2020-06-07 17:23:22.958 ERROR --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

我搜索了所有可能有效的 Spring 和 Grails 组合,但找不到具体的无效组合。

我的依赖项是:

dependencies {
    // added the new way using Log4j2, yes, spring makes it easy
    compile "org.springframework.boot:spring-boot-starter-log4j2"

    // changed spring-boot-autoconfigure so that it would not
    // pull in the logback binding/implementation
    compile ('org.springframework.boot:spring-boot-autoconfigure') {
        exclude group: 'ch.qos.logback', module: 'logback-classic'
    }
    compile ('org.springframework.boot:spring-boot-starter') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    //
    compile group: 'org.springframework.security', name: 'spring-security-core', version: '5.3.2.RELEASE'
    compile group: 'org.springframework.security', name: 'spring-security-web', version: '5.3.2.RELEASE'


    // and finally, added the log4j2 binding/implementation
    compile "org.apache.logging.log4j:log4j-api:2.13.2"
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.2'

//    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:grails-web-boot"
    compile "org.grails:grails-logging"
    compile "org.grails:grails-plugin-rest"
    compile "org.grails:grails-plugin-databinding"
    compile "org.grails:grails-plugin-i18n"
    compile "org.grails:grails-plugin-services"
    compile "org.grails:grails-plugin-url-mappings"
    compile "org.grails:grails-plugin-interceptors"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:async"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:events"
    compile "org.grails.plugins:hibernate5"
    compile "org.hibernate:hibernate-core:5.1.10.Final"
    compile "org.grails.plugins:gsp"
    compile 'org.grails.plugins:spring-security-core:4.0.0'
    compile 'org.grails.plugins:mail:2.0.0'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'

    implementation 'com.squareup.okhttp3:okhttp:3.9.1'
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.9.1'

    console "org.grails:grails-console"
    profile "org.grails.profiles:web"

    runtime "org.glassfish.web:el-impl:2.1.2-b03"
    runtime "org.apache.tomcat:tomcat-jdbc"
    runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.14.2"
    runtime 'mysql:mysql-connector-java:5.1.29'

    testCompile "org.grails:grails-gorm-testing-support"
    testCompile "org.grails.plugins:geb"
    testCompile "org.grails:grails-web-testing-support"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}dependencies {
    // added the new way using Log4j2, yes, spring makes it easy
    compile "org.springframework.boot:spring-boot-starter-log4j2"

    // changed spring-boot-autoconfigure so that it would not
    // pull in the logback binding/implementation
    compile ('org.springframework.boot:spring-boot-autoconfigure') {
        exclude group: 'ch.qos.logback', module: 'logback-classic'
    }
    compile ('org.springframework.boot:spring-boot-starter') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    //
    compile group: 'org.springframework.security', name: 'spring-security-core', version: '5.3.2.RELEASE'
    compile group: 'org.springframework.security', name: 'spring-security-web', version: '5.3.2.RELEASE'


    // and finally, added the log4j2 binding/implementation
    compile "org.apache.logging.log4j:log4j-api:2.13.2"
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.2'

//    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:grails-web-boot"
    compile "org.grails:grails-logging"
    compile "org.grails:grails-plugin-rest"
    compile "org.grails:grails-plugin-databinding"
    compile "org.grails:grails-plugin-i18n"
    compile "org.grails:grails-plugin-services"
    compile "org.grails:grails-plugin-url-mappings"
    compile "org.grails:grails-plugin-interceptors"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:async"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:events"
    compile "org.grails.plugins:hibernate5"
    compile "org.hibernate:hibernate-core:5.1.10.Final"
    compile "org.grails.plugins:gsp"
    compile 'org.grails.plugins:spring-security-core:4.0.0'
    compile 'org.grails.plugins:mail:2.0.0'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'

    implementation 'com.squareup.okhttp3:okhttp:3.9.1'
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.9.1'

    console "org.grails:grails-console"
    profile "org.grails.profiles:web"

    runtime "org.glassfish.web:el-impl:2.1.2-b03"
    runtime "org.apache.tomcat:tomcat-jdbc"
    runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.14.2"
    runtime 'mysql:mysql-connector-java:5.1.29'

    testCompile "org.grails:grails-gorm-testing-support"
    testCompile "org.grails.plugins:geb"
    testCompile "org.grails:grails-web-testing-support"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}

升级之前,一切正常。所有升级都是在依赖项中完成的,并且代码没有进行太多更改。仅某些密码加密。

有人看到过什么或者知道如何解决这个问题吗?

谢谢

最佳答案

问题出在版本 compile "org.hibernate:hibernate-core:5.1.10.Final" 中 - 可能有问题,在更改为 compile "org.hibernate:hibernate- core:5.4.10.Final" 一切正常。

此外,一个域类具有 静态映射= { 缓存真 } 这也不再起作用了。

关于java - 移动到新的 spring 后无法启动服务器启动 Tomcat 上下文时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62246890/

相关文章:

java - 在 primefaces 中显示嵌套 bean,JSF web 应用程序

java - 抽象父类(super class)的 Hibernate (JPA) 继承映射

hibernate - 从 JPQL 查询返回 JPA 实体的子集作为映射数组?

Java GC 问题 : How could an object become unreachable while one of its methods is still being executed?

java - 我想通过使用算术级数公式更有效地解决 Project Euler #1,但我的算法返回的答案略有偏差

java - 使用 Mockito 在客户端测试 POST 请求

Spring Bean 使用 @Transactional 卡在方法上

mysql - 带有 hibernate 的 Spring 数据 : multiple row insert in one-to-many entity without cascade

java - 我如何开始使用这个 Java 库?

java - 在自定义 spring boot 登录表单上显示错误登录消息