0

I have a spring web application and using tomcat to deploy my application(war). I have some initialization code which does database upgrade using liquibase.If any exception occurs, the deployment fails as expected, But tomcat is coming up and any request to my application is resulting in 404 not found error.

But I want some fail fast way to stop the tomcat as soon as the deployment fails. is there any way to achieve this?

Deepu
  • 39
  • 1
  • 6

2 Answers2

0

Let try catch your exceptions and shutdown Tomcat by Java code in finally block.

hoapham
  • 180
  • 5
  • 10
  • How do I shutdown the tomcat apart from calling system.exit(0)? any better way to some shutdown hook or something? – Deepu Jan 25 '18 at 16:29
  • I recommend that don't use System.exit(int) because it kills your JVM, invoking this from Tomcat, will not only kill your application but most likely server itself. If that Tomcat also host other critical application, either shutdown your tomcat is bad idea. Let shutdown application that failed to acquire necessary resources. – hoapham Jan 26 '18 at 10:50
0

You can the function exist of System clas

System.exit(1);

The function exit take in param an int that will be the status.

Youssouf Maiga
  • 6,701
  • 7
  • 26
  • 42