0

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)

  • See if this might be helpful: https://www.baeldung.com/spring-beandefinitionstoreexception – dbreaux Sep 10 '22 at 14:36
  • Also, a slightly cleaner way to do the same thing, but would presumably have the same problem, is `WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext( event.getServletContext());` – dbreaux Sep 10 '22 at 14:38
  • Thanks for suggesting this, but still i got some error. Exception in TomcatstopListener Failed to read candidate component class: file \myapp\WEB-INF\classes\com\ScheduleJobController.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 11560 – rajeshp808 Sep 21 '22 at 08:25
  • That looks like a totally different error, yes? You might open a separate question, with the additional relevant details. – dbreaux Sep 21 '22 at 13:48
  • yes, it look different error, but related to spring context only. Updated my post with more error details. – rajeshp808 Sep 26 '22 at 07:22

0 Answers0