KotlinCordaSpringBoot应用导致SLF4J StackOverflowError。

问题描述 投票:0回答:1

我不太清楚为什么这个项目会停止工作。我的项目在几周前还在工作,但我刚试着再次运行它,却得到一个关于日志记录的StackOverflowError。

我正在运行的应用程序并没有引起这个问题,因为我已经用空的东西替换了主方法。

class Application {
    companion object {
        @JvmStatic
        fun main(vararg args: String) {
            println("Hello, world.");
        }
    }
}

在控制台中得到以下错误(我删掉了大部分内容,因为它只是重复了导致StackOverflowError的内容)。

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/user/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.11.2/4d44e4edc4a7fb39f09b95b09f560a15976fa1ba/log4j-slf4j-impl-2.11.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/user/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.StackOverflowError
    at org.apache.logging.log4j.util.StackLocator.getCallerClass(StackLocator.java:121)
    at org.apache.logging.log4j.util.StackLocatorUtil.getCallerClass(StackLocatorUtil.java:55)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:42)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:39)
    at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37)
    at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:52)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:39)
    at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37)
    at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:52)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:39)
    at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37)
    at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:52)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)

这些是我的gradle依赖项。

dependencies {
    // Main
    implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
    implementation "$corda_group:corda-core:$corda_release_version"
    implementation "$corda_group:corda-rpc:$corda_release_version"
    implementation "$springboot_group:spring-boot-starter-web:$springboot_release_version"

    implementation "$newco_group:newco-kotlin-core:$newco_kotlin_core_release_version"
    implementation "$newco_group:newco-kotlin-libex:$newco_libex_release_version"
    implementation "$newco_group:newco-kotlin-libex-services:$newco_libex-services_release_version"
    implementation "$newco_group:newco-corda-fintex-contract:$newco_fintex_release_version"
    implementation "$newco_group:newco-corda-fintex-workflow:$newco_fintex_release_version"
    implementation "$newco_group:newco-corda-fintex-integration:$newco_fintex_release_version"

    implementation project(":cordapp-contract")
    implementation project(":cordapp-workflow")
    implementation project(":cordapp-integration")

    // Test
    testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
    testImplementation "$junit_group:junit-jupiter-api:$junit_version"
    testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
    testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}

我试着把这个添加到gradle中,但没有用。

configurations {
    all {
        exclude module: 'slf4j-log4j12'
        exclude module: 'jms'
        exclude module: 'jmxtools'
        exclude module: 'jmxri'
    }
}

有什么办法吗?- 我不知道该从哪里开始

spring-boot kotlin log4j slf4j corda
1个回答
1
投票

在初始化日志接口&实现时,似乎有一个无限循环,这就是导致StackOverflowError的原因。

从日志输出中可以看出,你的classpath上有多个日志绑定。

SLF4J:类路径包含多个SLF4J绑定。

从您的依赖中排除log4j或logback应该可以解决您的问题。

确保你使用了正确的排除引用。根据日志输出,我认为你应该排除掉 log4j-slf4j-impl 而不是 slf4j-log4j12 (或类似的东西)。

© www.soinside.com 2019 - 2024. All rights reserved.