Issue
In my spring boot application, we are connecting to our oracle database. After trying to connect to DB 2-3 times, I want my application to shut down automatically if the DB connection is failed. How can I do it?
Solution
There are few ways but one quick way is to use exit
method of SpringApplication.
public YourClass{
@Autowired
ApplicationContext ctx;
public dbconnectivityCheck{
//if connection attempts failed
SpringApplication.exit(ctx);
}
}
Answered By - Ashish Patil
Answer Checked By - Robin (JavaFixing Admin)