earldouglas / xsbt-web-plugin

Servlet support for sbt
BSD 3-Clause "New" or "Revised" License
384 stars 105 forks source link

Catalina and spring class loading problem #873

Open kojoa opened 4 months ago

kojoa commented 4 months ago

Hello,

I have no idea if this anything to do with this plugin so feel free to throw this away. Anyway, been debugging old Spring application that needs to be upgraded from 4 to 5. Old project has been using this plugin to run the application on Tomcat without problems. However, after upgrading to Spring 5, I keep geting errors like:

2024-03-07 18:10:31,138 WARN  [main] org.springframework.web.context.support.XmlWebApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0' defined in ServletContext resource [/WEB-INF/index-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Constructor threw exception; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method 'reactor.core.publisher.Mono reactor.core.publisher.Mono.from(org.reactivestreams.Publisher)' the class loader org.apache.catalina.loader.ParallelWebappClassLoader @3c9bfddc of the current class, org/springframework/core/ReactiveAdapterRegistry$ReactorRegistrar, and the class loader 'app' for the method's defining class, reactor/core/publisher/Mono, have different Class objects for the type org/reactivestreams/Publisher used in the signature (org.springframework.core.ReactiveAdapterRegistry$ReactorRegistrar is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @3c9bfddc, parent loader 'app'; reactor.core.publisher.Mono is in unnamed module of loader 'app')
2024-03-07 18:10:31,140 ERROR [main] org.springframework.web.servlet.DispatcherServlet: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0' defined in ServletContext resource [/WEB-INF/index-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Constructor threw exception; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method 'reactor.core.publisher.Mono reactor.core.publisher.Mono.from(org.reactivestreams.Publisher)' the class loader org.apache.catalina.loader.ParallelWebappClassLoader @3c9bfddc of the current class, org/springframework/core/ReactiveAdapterRegistry$ReactorRegistrar, and the class loader 'app' for the method's defining class, reactor/core/publisher/Mono, have different Class objects for the type org/reactivestreams/Publisher used in the signature (org.springframework.core.ReactiveAdapterRegistry$ReactorRegistrar is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @3c9bfddc, parent loader 'app'; reactor.core.publisher.Mono is in unnamed module of loader 'app')

and

Illegal reflective access by org.apache.catalina.loader.WebappClassLoaderBase (file:/Users/xxxx/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/heroku/webapp-runner/9.0.41.0/webapp-runner-9.0.41.0.jar) to field java.io.ObjectStreamClass$Caches.localDescs

i have been trying different minor versions of spring and heroku webapp runner. Also tried looking into dependency tree for reactive-streams conflicts but there seems to be none.

Any advice is welcome as I'm stuck here. Thanks for reading.

earldouglas commented 4 months ago

Oof, that looks like a fun bit of debugging.

Would it be possible to switch from Tomcat to Jetty just to see if the errors are any different?

kojoa commented 4 months ago

Thanks for quick response. It's quite a bit refactoring but I'll give it a try.