'Upgrade Spring Web MVC 4.1.6.RELEASE to 5.2.21.RELEASE -> NoClassDefFoundError: .../web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter
I am upgrading my Spring project 4.1.6 to 5.2.21. But now when I run my Tomcat 8.5.65 I catch this message error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configPersistence': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:409) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1181) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spring-context-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:401) ~[spring-web-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:292) ~[spring-web-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103) ~[spring-web-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4703) ~[catalina.jar:8.5.65]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5168) ~[catalina.jar:8.5.65]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[catalina.jar:8.5.65]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743) ~[catalina.jar:8.5.65]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719) ~[catalina.jar:8.5.65]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705) ~[catalina.jar:8.5.65]
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1767) ~[catalina.jar:8.5.65]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_301]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_301]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_301]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_301]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:286) ~[tomcat-coyote.jar:8.5.65]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[?:1.8.0_301]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[?:1.8.0_301]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:483) ~[catalina.jar:8.5.65]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431) ~[catalina.jar:8.5.65]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_301]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_301]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_301]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_301]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:286) ~[tomcat-coyote.jar:8.5.65]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[?:1.8.0_301]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[?:1.8.0_301]
at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468) ~[?:1.8.0_301]
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) ~[?:1.8.0_301]
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) ~[?:1.8.0_301]
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) ~[?:1.8.0_301]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_301]
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408) ~[?:1.8.0_301]
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) ~[?:1.8.0_301]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_301]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_301]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_301]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_301]
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) ~[?:1.8.0_301]
at sun.rmi.transport.Transport$1.run(Transport.java:200) ~[?:1.8.0_301]
at sun.rmi.transport.Transport$1.run(Transport.java:197) ~[?:1.8.0_301]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_301]
at sun.rmi.transport.Transport.serviceCall(Transport.java:196) ~[?:1.8.0_301]
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573) ~[?:1.8.0_301]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834) ~[?:1.8.0_301]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688) ~[?:1.8.0_301]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_301]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687) [?:1.8.0_301]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_301]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_301]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_301]
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter
at org.springframework.hateoas.config.HypermediaSupportBeanDefinitionRegistrar$Jackson2ModuleRegisteringBeanPostProcessor.postProcessBeforeInitialization(HypermediaSupportBeanDefinitionRegistrar.java:244) ~[spring-hateoas-0.17.0.RELEASE.jar:?]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:415) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1791) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
... 67 more
Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1372) ~[catalina.jar:8.5.65]
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1195) ~[catalina.jar:8.5.65]
at org.springframework.hateoas.config.HypermediaSupportBeanDefinitionRegistrar$Jackson2ModuleRegisteringBeanPostProcessor.postProcessBeforeInitialization(HypermediaSupportBeanDefinitionRegistrar.java:244) ~[spring-hateoas-0.17.0.RELEASE.jar:?]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:415) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1791) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.21.RELEASE.jar:5.2.21.RELEASE]
... 67 more
Any ideas?
Thanks in advance!
Solution 1:[1]
The version of the hateoas you are using is: hateoas-0.17.0.RELEASE
Most probably upgrading Spring HATEOAS dependency should resolve your issue.
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
Ref - https://github.com/springfox/springfox/issues/2303
FYI
If possible upgrade your spring version to 5.3.x and hateoas accordingly
5.3.x is the final feature branch of the 5th generation and the latest production line (GA as of October 2020), with long-term support provided on JDK 8, JDK 11, JDK 17.
5.2.x is the previous production line (GA as of September 2019), to be actively supported until the end of 2021.
JDK Version Range
- Spring Framework 6.0.x: JDK 17-21 (expected)
- Spring Framework 5.3.x: JDK 8-19 (expected)
- Spring Framework 5.2.x: JDK 8-15
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |