I am using open JDK11, Spring 3.1 version, with below code. Using tomcat 8.5
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
public class TomcatStopListener extends ContextLoaderListener {
public void contextDestroyed(ServletContextEvent event) {
try {
WebApplicationContext context = (WebApplicationContext) event.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
Getting below runtime exception for the above code.
java.lang.ClassCastException: org.springframework.beans.factory.BeanDefinitionStoreException incompatible with org.springframework.web.context.WebApplicationContext
at com.nsn.servlets.TomcatStopListener.contextDestroyed(TomcatStopListener.java:28)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4811)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5467)
please suggest, thank you
**
Update 26th Sept 2022
** I have updated the below api, but getting array index out of bound exception.
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext( event.getServletContext());
Caused by: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 11560 at org.springframework.asm.ClassReader.readClass(Unknown Source) at org.springframework.asm.ClassReader.accept(Unknown Source) at org.springframework.asm.ClassReader.accept(Unknown Source) at org.springframework.core.type.classreading.SimpleMetadataReader.(SimpleMetadataReader.java:59) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80) at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101) at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:237)