无法在 grails 4.0.1 中配置 spring bean

问题描述

我有一个项目,我已经有一段时间没有碰过了,我们决定重新启动它。该项目和 API 使用 Grails 4 编写。

上次(几个月前)它运行良好且构建良好。现在,如果我几乎运行任何 grails 命令,我都会收到以下错误

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-09 22:34:20.225 ERROR --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION Failed TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    okio.Segment.writeto(Segment.kt:169)

The following method did not exist:

    kotlin.collections.ArraysKt.copyInto([B[BIII)[B

The method's class,kotlin.collections.ArraysKt,is available from the following locations:

    jar:file:/Users/shurikag/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.71/d9717625bb3c731561251f8dd2c67a1011d6764c/kotlin-stdlib-1.2.71.jar!/kotlin/collections/ArraysKt.class

It was loaded from the following location:

    file:/Users/shurikag/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.71/d9717625bb3c731561251f8dd2c67a1011d6764c/kotlin-stdlib-1.2.71.jar


Action:

Correct the classpath of your application so that it contains a single,compatible version of kotlin.collections.ArraysKt


> Task :dbmUpdate Failed
5 actionable tasks: 5 executed
<-------------> 0% WAITING
> IDLE
Context Failed to load: Error creating bean with name 'restTokenValidationFilter': Cannot resolve reference to bean 'restAuthenticationProvider' while setting bean property 'restAuthenticationProvider'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restAuthenticationProvider': Cannot resolve reference to bean 'tokenStorageService' while setting bean property 'tokenStorageService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenStorageService': Cannot resolve reference to bean 'auth0APIService' while setting bean property 'auth0APIService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'auth0APIService': Cannot resolve reference to bean 'authApi' while setting bean property 'authAPI'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authApi': Bean instantiation via constructor Failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.auth0.client.auth.AuthAPI]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: kotlin.collections.ArraysKt.copyInto([B[BIII)[B

FAILURE: Build Failed with an exception.

* What went wrong:
Execution Failed for task ':dbmUpdate'.
> Process 'command '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java'' finished with non-zero exit value 1

我假设它与依赖版本有关。检查了所有内容 - 甚至从另一个有效的项目中复制...没有帮助。

这是我的resources.groovy

import com.auth0.client.auth.AuthAPI
import edvengo.auth0.Auth0APIService
import edvengo.auth0.Auth0TokenStorageService
import edvengo.auth0.Auth0TokenVerificationService
import edvengo.auth0.Auth0UserResolverService
import edvengo.security.UserPasswordEncoderListener
import grails.plugin.springsecurity.rest.RestAuthenticationProvider

// Place your Spring DSL code here
beans = {

    userPasswordEncoderListener(UserPasswordEncoderListener)

    authApi(AuthAPI) { beanDeFinition ->
        beanDeFinition.constructorArgs = [
                '${edvengo.auth0.api.domain}','${edvengo.auth0.api.clientId}','${edvengo.auth0.api.clientSecret}'
        ]
    }

    auth0APIService(Auth0APIService) {
        authAPI = ref('authApi')
    }

    auth0TokenVerificationService(Auth0TokenVerificationService)

    auth0UserResolverService(Auth0UserResolverService)

    tokenStorageService(Auth0TokenStorageService) {
        jwtService = ref('jwtService')
        userDetailsService = ref('userDetailsService')
        auth0TokenVerificationService = ref('auth0TokenVerificationService')
        auth0APIService = ref('auth0APIService')
        auth0UserResolverService = ref('auth0UserResolverService')
    }

    /* restAuthenticationProvider */
    restAuthenticationProvider(RestAuthenticationProvider) {
        tokenStorageService = ref('tokenStorageService')
        useJwt = false
        jwtService = ref('jwtService')
    }

}

此时,我的假设是问题只与authApi bean有关。可能带有构造函数参数。检查环境变量是否正确定义。

还有什么可能是原因?

仅供参考。我的build.gradle

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://repo.grails.org/grails/core" }
        jcenter()
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsversion"
        classpath "org.grails.plugins:views-gradle:2.0.2"
        classpath "org.grails.plugins:hibernate5:7.0.4"
        classpath 'org.grails.plugins:database-migration:3.1.0.RC1'
    }
}

version "0.2"
group "edvengo.api"

// apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.plugins.views-json"

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

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

dependencyManagement {
    imports {
        mavenBom 'com.amazonaws:aws-java-sdk-bom:1.12.1'
    }
}

dependencies {
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    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-plugin-url-mappings"
    compile "org.grails:grails-plugin-rest"
    compile "org.grails:grails-plugin-codecs"
    compile "org.grails:grails-plugin-interceptors"
    compile "org.grails:grails-plugin-services"
    compile "org.grails:grails-plugin-datasource"
    compile "org.grails:grails-plugin-databinding"
    compile "org.grails:grails-web-boot"
    compile "org.grails:grails-logging"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:async"
    compile "org.grails.plugins:spring-security-rest:3.0.1"
    compile "org.grails.plugins:views-json"
    compile "org.grails.plugins:views-json-templates"
    compile "org.grails.plugins:events"
    compile "org.grails.plugins:hibernate5"
    compile "org.hibernate:hibernate-core:5.4.18.Final"
    compileOnly "io.micronaut:micronaut-inject-groovy"
    console "org.grails:grails-console"
    profile "org.grails.profiles:rest-api"
    runtime "org.glassfish.web:el-impl:2.1.2-b03"
    runtime "com.h2database:h2"
    runtime "org.apache.tomcat:tomcat-jdbc"
    runtime "javax.xml.bind:jaxb-api:2.3.1"
    testCompile "io.micronaut:micronaut-inject-groovy"
    testCompile "org.grails:grails-gorm-testing-support"
    testCompile "org.mockito:mockito-core"
    testCompile "io.micronaut:micronaut-http-client"
    testCompile "org.grails:grails-web-testing-support"
    testCompile "org.grails:views-json-testing-support"
    testCompile "org.hibernate.validator:hibernate-validator:6.0.20.Final"

    compile "com.amazonaws:aws-java-sdk-s3"

    compile "org.grails.plugins:postgresql-extensions:7.0.0"
    compile "org.postgresql:postgresql:42.2.20"
    compile 'org.grails.plugins:database-migration:3.1.0.RC1'
    compile 'org.liquibase:liquibase-core:3.6.1'

    compile "com.auth0:auth0:1.31.0"
    compile "com.auth0:jwks-rsa:0.18.0"

    compile 'com.papertrailapp:logback-syslog4j:1.0.0'
    compile "com.stripe:stripe-java:20.56.0"

    compile "com.sendinblue:sib-api-v3-sdk:5.2.0"

    runtime "org.grails.plugins:async:4.0.0"
    compile "org.grails:grails-datastore-gorm-async"

    implementation "com.squareup.okhttp3:okhttp:4.9.0"
    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.72'

}

bootRun {
    ignoreExitValue true
    jvmArgs(
            '-Dspring.output.ansi.enabled=always','-noverify','-XX:TieredStopAtLevel=1','-Xmx1024m')
    sourceResources sourceSets.main
    String springProfilesActive = 'spring.profiles.active'
    systemProperty springProfilesActive,System.getProperty(springProfilesActive)
}

tasks.withType(GroovyCompile) {
    configure(groovyOptions) {
        forkOptions.jvmArgs = ['-Xmx1024m']
    }
}

sourceSets {
    main {
        resources {
            srcDir 'grails-app/migrations'
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)