Is it possible to exclude Java Servlet to exclude application launch?

I have a Java servlet marked with a sign load-on-startupand implemented init(). As part of the logic, init()there is a call validate()that determines whether things are really real.

My problem is that if it validate()determines that everything is bad, I want the application not to start as a warning that something needs to be fixed. I tried to quit ServletException, and while this information was sent to my console, I could still send traffic in the application, and it responded.

Finally, my hands are somewhat tied to the timing. My servlet extends the base class, which sets up the content I'm trying to test.

If there is a solution that I will need to run on Tomcat and WebLogic.

+4
source share
1 answer

As stated above, Luigi Mendoza is a good place to initialize web applications in the ServletContextListener instead of relying on the init method of a separate servlet.

The web application context is destroyed (at least in Tomcat 6) when an exception (runtime exception) is thrown from the listenerIntialized context.

It is best to translate the initialization logic into a ServletContextListener (you can define multiple listeners for each web application, and they execute in the order in which they are registered in web.xml). And keep only the request processing logic in the servlet.

+3
source

Source: https://habr.com/ru/post/1502631/


All Articles