akkinoc / logback-access-spring-boot-starter

Spring Boot Starter for Logback-access.
Apache License 2.0
194 stars 33 forks source link

java.lang.NoSuchMethodError: 'java.util.SortedMap kotlin.collections.MapsKt.sortedMapOf(java.util.Comparator, kotlin.Pair[])' #109

Closed theamith closed 1 year ago

theamith commented 2 years ago

I am trying to use logback-access-spring-boot-starter in an existing Java-tomcat-spring-mvc based spring boot application. Since this library used kotlin, I have added kotlin dependencies and the compilation succeeded. Although getting below error after successfully started the tomcat application

java.lang.NoSuchMethodError: 'java.util.SortedMap kotlin.collections.MapsKt.sortedMapOf(java.util.Comparator, kotlin.Pair[])'
        at dev.akkinoc.spring.boot.logback.access.tomcat.LogbackAccessTomcatEventSource$requestHeaderMap$2.invoke(LogbackAccessTomcatEventSource.kt:98)
        at dev.akkinoc.spring.boot.logback.access.tomcat.LogbackAccessTomcatEventSource$requestHeaderMap$2.invoke(LogbackAccessTomcatEventSource.kt:97)
        at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
        at dev.akkinoc.spring.boot.logback.access.tomcat.LogbackAccessTomcatEventSource.getRequestHeaderMap(LogbackAccessTomcatEventSource.kt:97)
        at dev.akkinoc.spring.boot.logback.access.LogbackAccessEventSource$Fixed.<init>(LogbackAccessEventSource.kt:201)
        at dev.akkinoc.spring.boot.logback.access.LogbackAccessEventSource.fix(LogbackAccessEventSource.kt:156)
        at dev.akkinoc.spring.boot.logback.access.LogbackAccessEvent.prepareForDeferredProcessing(LogbackAccessEvent.kt:159)
        at net.logstash.logback.appender.AsyncDisruptorAppender.prepareForDeferredProcessing(AsyncDisruptorAppender.java:603)
        at net.logstash.logback.appender.AsyncDisruptorAppender.append(AsyncDisruptorAppender.java:492)
        at net.logstash.logback.appender.AsyncDisruptorAppender.append(AsyncDisruptorAppender.java:99)
        at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:84)
        at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
        at ch.qos.logback.access.spi.AccessContext.callAppenders(AccessContext.java:40)
        at dev.akkinoc.spring.boot.logback.access.LogbackAccessContext.emit(LogbackAccessContext.kt:64)
        at dev.akkinoc.spring.boot.logback.access.tomcat.LogbackAccessTomcatValve.log(LogbackAccessTomcatValve.kt:75)
        at org.apache.catalina.core.AccessLogAdapter.log(AccessLogAdapter.java:48)
        at org.apache.catalina.core.StandardEngine.logAccess(StandardEngine.java:279)
        at org.apache.catalina.core.ContainerBase.logAccess(ContainerBase.java:1059)
        at org.apache.catalina.core.ContainerBase.logAccess(ContainerBase.java:1059)
        at org.apache.catalina.connector.CoyoteAdapter.log(CoyoteAdapter.java:484)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:404)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Thread.java:829)

Common build.gradle file in which the kotlin and logback dependencies added

plugins {
        id 'java-library'
}

group = 'in.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
        compileOnly {
                extendsFrom annotationProcessor
        }
}

repositories {
    mavenCentral()
}

dependencies {
        compileOnly 'org.projectlombok:lombok:1.18.12'
        annotationProcessor 'org.projectlombok:lombok:1.18.12'
        api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.2'
        api 'com.github.dozermapper:dozer-core:6.5.0'
        api 'com.vladmihalcea:hibernate-types-52:2.10.1'
        api 'org.springdoc:springdoc-openapi-webmvc-core:1.2.32'
        api 'org.springframework.cloud:spring-cloud-starter-sleuth:2.2.5.RELEASE'
        api 'org.springframework.cloud:spring-cloud-starter-zipkin:2.2.5.RELEASE'
        api 'net.logstash.logback:logstash-logback-encoder:7.0'
        api 'ch.qos.logback:logback-access:1.2.3'
        api 'dev.akkinoc.spring.boot:logback-access-spring-boot-starter:3.1.1'
        api 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0'
        api 'org.jetbrains.kotlin:kotlin-reflect:1.6.0'
        api 'com.fasterxml.jackson.module:jackson-module-kotlin'
        api 'com.cronutils:cron-utils:9.1.5'
        api 'org.springframework.boot:spring-boot-starter-data-jpa:2.3.4.RELEASE'
        api 'org.springframework.boot:spring-boot-starter-data-mongodb:2.3.4.RELEASE'
        implementation 'commons-lang:commons-lang:2.6'
        compileOnly 'org.springframework.boot:spring-boot-starter-data-rest:2.4.1'
        compileOnly 'org.springframework.boot:spring-boot-starter-oauth2-resource-server:2.3.4.RELEASE'
        compileOnly 'org.springframework.boot:spring-boot-starter-web:2.3.4.RELEASE'
        compileOnly 'org.springframework.cloud:spring-cloud-starter-openfeign:2.2.5.RELEASE'
}

Application's build.gradle

plugins {
        id 'java'
        id 'application'
        id 'org.springframework.boot' version '2.3.4.RELEASE'
        id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}

group = 'in.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
mainClassName = 'in.test.testservice.TestServiceApplication'

configurations {
        compileOnly {
                extendsFrom annotationProcessor
        }
}

repositories {
        mavenCentral()
        maven { url 'https://jitpack.io' }
}

ext {
        set('springCloudVersion', "Hoxton.SR8")
}

dependencies {
        compileOnly 'org.projectlombok:lombok:1.18.12'
        annotationProcessor 'org.projectlombok:lombok:1.18.12'
        implementation project (':spring-backend-common')
        implementation 'com.github.alturkovic.distributed-lock:distributed-lock-core:1.4.2'
        implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation 'org.springframework.boot:spring-boot-starter-actuator'
        implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
        implementation 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix'
        implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
        implementation 'org.springframework.cloud:spring-cloud-starter-config'
        testImplementation('org.springframework.boot:spring-boot-starter-test') {
                exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
                exclude group: 'org.mockito', module: 'mockito-core'
                exclude group: 'org.mockito', module: 'mockito-junit-jupiter'
        }
        testImplementation('org.mockito:mockito-core:3.6.0')
        testImplementation('org.mockito:mockito-junit-jupiter:3.6.0')
        testImplementation('org.mockito:mockito-inline:3.6.0')
        runtimeOnly 'org.postgresql:postgresql'
}

dependencyManagement {
        imports {
                mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        }
}

test {
        useJUnitPlatform()
}
akkinoc commented 2 years ago

Sorry, I'm not fluent in Gradle. Would you please provide a minimal sample project and steps to reproduce this issue?

gjain-sag commented 2 years ago

Even i am facing the same issue while trying to add this dependency with Spring boot and undertow embedded server. Any suggestions would be appreciated.

akkinoc commented 2 years ago

Can you tell me the version of your Spring Boot (or Kotlin)?

logback-access-spring-boot-starter v3.1/v3.2 requires Spring Boot v2.6 (Kotlin v1.6). Please upgrade to Spring Boot v2.6 (Kotlin v1.6).

Note: java.util.SortedMap kotlin.collections.MapsKt.sortedMapOf(java.util.Comparator, kotlin.Pair[]) is a method introduced in Kotlin v1.4.

gjain-sag commented 2 years ago

Spring boot version : 2.2.7.RELEASE I can't upgrade my spring boot as there are other dependencies, do we have an supported version for logback-starter against against spring boot 2.2.7RELEASE

akkinoc commented 2 years ago

It may work with logback-access-spring-boot-starter v2.11.0. https://github.com/akkinoc/logback-access-spring-boot-starter/tree/v2.11.0

However, please note that I have no plans to update other than the latest version.

akkinoc commented 1 year ago

This issue is inactive, so I close it. If you still have problems, please open a new issue.