Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch.qos.logback.access:tomcat has non-optional Tomcat dependencies #17

Open
jonatan-ivanov opened this issue Aug 20, 2024 · 6 comments
Open
Assignees
Labels
DONE Issue was fixed IN_PROGRESS
Milestone

Comments

@jonatan-ivanov
Copy link

jonatan-ivanov commented Aug 20, 2024

I'm migrating from ch.qos.logback:logback-access to ch.qos.logback.access:tomcat.
Or from

ch.qos.logback:logback-access:1.4.14
ch.qos.logback:logback-core:1.5.6

to

ch.qos.logback.access:common:2.0.3
ch.qos.logback.access:tomcat:2.0.3
ch.qos.logback:logback-core:1.5.7

It seems that ch.qos.logback.access:tomcat:2.0.3 brings in Tomcat 10.0.x (tomcat-catalina and tomcat-coyote) as its compile time dependency so I end up with these on my classpath:

org.apache.tomcat:tomcat-api:10.0.27
org.apache.tomcat:tomcat-catalina:10.0.27
org.apache.tomcat:tomcat-coyote:10.0.27
org.apache.tomcat:tomcat-el-api:10.1.26
org.apache.tomcat:tomcat-jaspic-api:10.0.27
org.apache.tomcat:tomcat-jni:10.0.27
org.apache.tomcat:tomcat-jsp-api:10.1.26
org.apache.tomcat:tomcat-juli:10.0.27
org.apache.tomcat:tomcat-servlet-api:10.1.26
org.apache.tomcat:tomcat-util-scan:10.0.27
org.apache.tomcat:tomcat-util:10.0.27

The problem is that I'm using Tomcat 10.1.x instead with Spring Boot 3.3.x which not just brings in Tomcat 10.1.x but does not seem to be compatible with 10.0.x. Also, Tomcat was an optional dependency for ch.qos.logback:logback-access:1.4.14.

Excluding Tomcat from ch.qos.logback.access:tomcat seems to resolve the issue and this might be the case with jakarta.servlet too:

implementation('ch.qos.logback.access:tomcat:latest.release') {
    exclude group: 'org.apache.tomcat'
    exclude group: 'jakarta.servlet'
}

Let me leave here the whole error message in case someone gets the same:

2024-08-20T21:23:49.489Z  INFO 29479 --- [tea-service] [main] [                                                 ] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-08-20T21:23:49.505Z ERROR 29479 --- [tea-service] [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:

    org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer.customizeMaxQueueCapacity(TomcatWebServerFactoryCustomizer.java:170)

The following method did not exist:

    'void org.apache.coyote.AbstractProtocol.setMaxQueueSize(int)'

The calling method's class, org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer, was loaded from the following location:

    jar:file:/Users/jivanov/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/3.3.2/6a9ab910b00f0b504a5903e3680ac10018da6247/spring-boot-autoconfigure-3.3.2.jar!/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.class

The called method's class, org.apache.coyote.AbstractProtocol, is available from the following locations:

    jar:file:/Users/jivanov/.gradle/caches/modules-2/files-2.1/org.apache.tomcat/tomcat-coyote/10.0.27/88364bdfcf72b38981f4c3617736d0a48881006f/tomcat-coyote-10.0.27.jar!/org/apache/coyote/AbstractProtocol.class
    jar:file:/Users/jivanov/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/10.1.26/5e0fa06ca373ef0ca55e603291ea51b590c377ea/tomcat-embed-core-10.1.26.jar!/org/apache/coyote/AbstractProtocol.class

The called method's class hierarchy was loaded from the following locations:

    org.apache.coyote.AbstractProtocol: file:/Users/jivanov/.gradle/caches/modules-2/files-2.1/org.apache.tomcat/tomcat-coyote/10.0.27/88364bdfcf72b38981f4c3617736d0a48881006f/tomcat-coyote-10.0.27.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer and org.apache.coyote.AbstractProtocol
jonatan-ivanov added a commit to jonatan-ivanov/teahouse that referenced this issue Aug 20, 2024
@jonatan-ivanov
Copy link
Author

Also, it seems 10.0 reached EOL and not supported anymore:

Please note that Tomcat 10.0.x has reached end of life and is no longer supported. Vulnerabilities reported after 31 October 2022 were not checked against the 10.0.x branch and will not be fixed. Users should upgrade to 10.1.x or later to obtain security fixes.

https://tomcat.apache.org/security-10.html

@levente160396
Copy link

levente160396 commented Dec 10, 2024

Hi @jonatan-ivanov!
I'm facing the same issue, as you suggested I excluded org.apache.tomcat and the build was successful., but during the startup, I'm getting.

 org.apache.catalina.LifecycleException: 
Failed to start component [ch.qos.logback.access.tomcat.LogbackValve[null]]

And
java.lang.NoClassDefFoundError: ch/qos/logback/access/spi/IAccessEvent\n\tat

I'm using spring-boot 3.4 ch.qos.logback.access.tomcat 2.0.3

Full logs
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165)\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:619)\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)\n\tat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:335)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1363)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1352)\n\tat .ServiceApplication$Companion.main(ServiceApplication.kt:20)\n\tat ServiceApplication.main(ServiceApplication.kt)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\n\tat java.base/java.lang.reflect.Method.invoke(Unknown Source)\n\tat org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:102)\n\tat org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:64)\n\tat org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:40)\nCaused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat\n\tat org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:147)\n\tat org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:107)\n\tat org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:516)\n\tat org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:222)\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:188)\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)\n\t... 16 common frames omitted\nCaused by: org.apache.catalina.LifecycleException: Failed to start component [ch.qos.logback.access.tomcat.LogbackValve[null]]\n\tat org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:402)\n\tat org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:179)\n\tat org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:157)\n\tat org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)\n\tat org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:773)\n\tat org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:203)\n\tat org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)\n\tat org.apache.catalina.core.StandardService.startInternal(StandardService.java:415)\n\tat org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)\n\tat org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:870)\n\tat org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)\n\tat org.apache.catalina.startup.Tomcat.start(Tomcat.java:437)\n\tat org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:128)\n\t... 21 common frames omitted\nCaused by: java.lang.NoClassDefFoundError: ch/qos/logback/access/spi/IAccessEvent\n\tat java.base/java.lang.Class.getDeclaredMethods0(Native Method)\n\tat java.base/java.lang.Class.privateGetDeclaredMethods(Unknown Source)\n\tat java.base/java.lang.Class.getMethodsRecursive(Unknown Source)\n\tat java.base/java.lang.Class.getMethod0(Unknown Source)\n\tat java.base/java.lang.Class.getMethod(Unknown Source)\n\tat ch.qos.logback.core.joran.util.StringToObjectConverter.getValueOfMethod(StringToObjectConverter.java:110)\n\tat ch.qos.logback.core.joran.util.StringToObjectConverter.followsTheValueOfConvention(StringToObjectConverter.java:119)\n\tat ch.qos.logback.core.joran.util.StringToObjectConverter.canBeBuiltFromSimpleString(StringToObjectConverter.java:42)\n\tat ch.qos.logback.core.joran.util.AggregationAssessor.computeRawAggregationType(AggregationAssessor.java:106)\n\tat ch.qos.logback.core.joran.util.AggregationAssessor.computeAggregationType(AggregationAssessor.java:62)\n\tat ch.qos.logback.core.joran.util.PropertySetter.computeAggregationType(PropertySetter.java:139)\n\tat ch.qos.logback.core.model.processor.ImplicitModelHandler.handle(ImplicitModelHandler.java:72)\n\tat ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:241)\n\tat ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:253)\n\tat ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:253)\n\tat ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:253)\n\tat ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:253)\n\tat ch.qos.logback.core.model.processor.DefaultProcessor.traversalLoop(DefaultProcessor.java:90)\n\tat ch.qos.logback.core.model.processor.DefaultProcessor.process(DefaultProcessor.java:106)\n\tat ch.qos.logback.core.joran.GenericXMLConfigurator.processModel(GenericXMLConfigurator.java:222)\n\tat ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:178)\n\tat ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:123)\n\tat ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:66)\n\tat ch.qos.logback.access.tomcat.LogbackValve.configureAsResource(LogbackValve.java:231)\n\tat ch.qos.logback.access.tomcat.LogbackValve.startInternal(LogbackValve.java:160)\n\tat org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)\n\t... 32 common frames omitted\nCaused by: java.lang.ClassNotFoundException: ch.qos.logback.access.spi.IAccessEvent\n\tat java.base/java.net.URLClassLoader.findClass(Unknown Source)\n\tat java.base/java.lang.ClassLoader.loadClass(Unknown Source)\n\tat

@ceki ceki self-assigned this Dec 10, 2024
@aggeboe
Copy link

aggeboe commented Dec 10, 2024

@levente160396 I'm also on spring boot 3.4.0 and the following works for me (gradle)

    implementation 'ch.qos.logback.access:common:2.0.3'
    implementation('ch.qos.logback.access:tomcat:2.0.3') {
        exclude group: 'org.apache.tomcat' // Remove when broken/non-optional tomcat dependencies are fixed (https://github.com/qos-ch/logback-access/issues/17)
    }

@levente160396
Copy link

levente160396 commented Dec 10, 2024

@levente160396 I'm also on spring boot 3.4.0 and the following works for me (gradle)

    implementation 'ch.qos.logback.access:common:2.0.3'
    implementation('ch.qos.logback.access:tomcat:2.0.3') {
        exclude group: 'org.apache.tomcat' // Remove when broken/non-optional tomcat dependencies are fixed (https://github.com/qos-ch/logback-access/issues/17)
    }

Yep, I removed those dependencies. The other exception is coming when I start the app.
I'm still analyzing it but I think it is because I am trying to add logback to the Tomcat.
Are tomcat cataling and tomcat coyota is required to create logbackValve ? That's why my startup fails

    @Bean
    fun embeddedServletContainerCustomizer(): WebServerFactoryCustomizer<*> =
        WebServerFactoryCustomizer { factory: WebServerFactory? ->
                    factory.setEngineValves(listOf(logbackValve))
            }
        }

here is my logbackValve configuration

@Bean
    @ConditionalOnProperty(name = ["access.logs.strategy.json"], havingValue = "true")
    fun logbackValve(): LogbackValve {
        val logValve = LogbackValve()
        logValve.filename = logbackAccess
        return logValve
    }

@ceki ceki added this to the 2.0.5 milestone Dec 10, 2024
@jonatan-ivanov
Copy link
Author

@levente160396
If you want a demo Spring Boot 3.4.0 example setup:

@ceki
Copy link
Member

ceki commented Dec 10, 2024

logback-access-tomcat/pom.xml now declares tomcat-catalina and tomcat-coyote in provided scope.

See also commit b9f5dcf

@ceki ceki added the DONE Issue was fixed label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DONE Issue was fixed IN_PROGRESS
Projects
None yet
Development

No branches or pull requests

4 participants