I have a servlet that loads when the server starts <load-on-startup>1</load-on-startup>in the init()servlet method , which I check for some parameter from the properties file. If the parameter is missing, I want to stop the initialization of the entire context.
<load-on-startup>1</load-on-startup>
init()
public void init(){ Readproperty pr = new ReadProperty(); if(!pr.parameterExists()){ //Edit: throw new UnavailableException("Testing Stopping Context") } }
What is the best way to do this? Now I want to move this code to my context listener class, so I'm looking for a better way to do this using the init () method.
You cannot stop the launch of a web application from a servlet.
-, ServletContextListener. contextInitialized() -.
ServletContextListener
contextInitialized()
Tomcat 7.0.x 8.0.x, Tomcat failCtxIfServletStartFails , -, - . ServletContextListener - .
failCtxIfServletStartFails
- . .