简体   繁体   中英

how to stop tomcat startup via servletcontextlistener

Is there a way to stop tomcat's startup if certain conditions don't occur?

For example, I'd like the contextInitialized method of a servletContextListener to check for various property file attributes as well as verify database connection, etc.

I've seen ways to shutdown tomcat via an MBean event but it requires the host, shutdown port. In my case I am hoping to have a single base class that can be used in multiple tomcats on the same server (each with their own shutdown port).

You could call Tomcat's shutdown port (typically 8005)... All you need is the port number and the text (eg 8005 and SHUTDOWN). Given you are on the host (the servletContextListener is running within Tomcat), you don't need a hostname. Localhost should do the trick.

An alternative is to have your Java code run a process on the server - invoke./shutdown.sh but that will involve knowing where that script is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM