On 22/06/17 11:57, Pesonen, Harri wrote: > 8.5.13. Maybe it is supported in 9 only.
Yes, throwOnFailure is 9.0.x only. It comes from https://bz.apache.org/bugzilla/show_bug.cgi?id=60152 What you can do in 8.5.x (and 9.0.x) is: <Context failCtxIfServletStartFails="true" > That will stop the web application starting if a load-on-startup servlet fails. Looking more at the changes for throwOnFailure, it isn't going to help because the Context failure in this case is viewed as a controlled failure. i.e. the Context detected a problem and put itself into the failed state. What you could do - which would work equally well in 8.5.x and 9.0.x is write a simple LifecycleListener, attach it to the Server and have it traverse the container hierarchy on the Lifecycle.AFTER_START_EVENT and check that all containers are started. If any are found in the FAILED state, shut Tomcat down. Mark > > -Harri > > -----Original Message----- > From: Mark Thomas [mailto:ma...@apache.org] > Sent: 22. kesäkuuta 2017 13:46 > To: Tomcat Users List <users@tomcat.apache.org> > Subject: Re: How to stop Tomcat if servlet fails to initialize > > On 22/06/17 11:44, Pesonen, Harri wrote: >> Hello, I tried adding throwOnFailure to conf/context.xml, but it did not >> work, I only got this: >> >> 10:34:23.582 (14) WRN> >> (org.apache.catalina.startup.SetContextPropertiesRule#begin) >> [SetContextPropertiesRule]{Context} Setting property 'throwOnFailure' to >> 'true' did not find a matching property. >> >> Maybe I did it wrong: >> >> <Context throwOnFailure="true" > > > I was working from the code rather than testing but this should work. > What version are you using? > > Mark > > >> >> -Harri >> >> -----Original Message----- >> From: Mark Thomas [mailto:ma...@apache.org] >> Sent: 21. kesäkuuta 2017 17:28 >> To: Tomcat Users List <users@tomcat.apache.org> >> Subject: Re: How to stop Tomcat if servlet fails to initialize >> >> On 21/06/17 13:33, Pesonen, Harri wrote: >>> Hello, if one servlet fails to initialize, meaning that >>> ServletContextListener.contextInitialized() throws exception, then Tomcat >>> still starts (but without the servlet). >> >> If ServletContextListener.contextInitialized(), the web application will >> not start. >> >> Servlets are not initialised until first used so they can't prevent an >> application from starting. The one exception is Servlets configured for >> "load on startup". Any failure of these servlets will cause the >> application to fail to start. >> >>> I found out that if servlet calls System.exit(1), then Tomcat dies. Is this >>> the only way to make this happen? >>> This does not work: >>> -Dorg.apache.catalina.startup.EXIT_ON_INIT_FAILURE=true >> >> You can try setting the (completely undocumented) throwOnFailure >> attribute for the Context, Host, Engine, Service and Server. >> >> The Context you can set in conf/context.xml so it applies to all web >> applications. >> >> Mark >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> For additional commands, e-mail: users-h...@tomcat.apache.org >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> For additional commands, e-mail: users-h...@tomcat.apache.org >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org