1

When a spring bean(e.g. Controller) fails in initialization, it propagates exception to FrameworkServlet of spring mvc. For this case, the servlet shuts down bean factory and throws a RuntimeException to web container. However, other servlets are still initialized and the server starts up. The error of FrameworkServlet is ignored.

Is there a way, I can propagate bean creation exceptions or servlet exceptions to other servlets? Can I fail tomcat startup if any of the servlet throws an exception?

Update: Adding a listener as mentioned here (Known way to stop server when spring context failed to load?) fails startup. I get following exception:

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

I have my context.xml at this location [/WEB-INF/spring/context.xml], which is configured in web.xml

Community
  • 1
  • 1
sanket shah
  • 21
  • 1
  • 4
  • 4
    looks like there is answer on your question https://stackoverflow.com/questions/25347593/known-way-to-stop-server-when-spring-context-failed-to-load – ivanenok Apr 12 '16 at 18:58
  • @ivanenok: This didn't solve my problem. I couldn't even start the server after adding the listener. Exception: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml] My context.xml is at location /WEB-INF/spring/context.xml, which is configured in web.xml – sanket shah Apr 12 '16 at 22:19
  • Have you configured ContextLoaderLister in your web.xml? If you have configured ContextLoaderListener in your web.xml and you haven't overridden its context location by your context.xml, you may get this kind of exception. – asg Apr 13 '16 at 02:15
  • I'd like this to be a setting, not a component – f.khantsis May 08 '16 at 19:15
  • Consider closing this question, it is a combination of asking the question from https://stackoverflow.com/questions/18656936/why-does-spring-continue-to-initialize-the-context-even-if-a-bean-fails-to-insta?rq=1 and implementing the solution proposed in https://stackoverflow.com/questions/25347593/known-way-to-stop-server-when-spring-context-failed-to-load. – jpierson Apr 06 '19 at 13:26

0 Answers0