Stop servlet context from initialization in init method

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.

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.

0
source share
2 answers

You cannot stop the launch of a web application from a servlet.

-, ServletContextListener. contextInitialized() -.

Tomcat 7.0.x 8.0.x, Tomcat failCtxIfServletStartFails , -, - . ServletContextListener - .

+2

- . .

-1

All Articles