I have a simple Spring Application, the configuration of which relies upon a SpringApplicationBuilder. To run the application, I simply call .run(args); however, if, for some reason, an error occurs during the application's lifecycle, I want the user to know about it and want to ensure all components of the application are shutdown, gracefully.
Is it possible to do this with a try-catch block (as per the posted code, below)? I have also read about the SpringApplicationRunListener but am unable to find a simple demonstration of its use.
Here's my code within the main method:
try {
configureApp(new SpringApplicationBuilder()).run(args);
} catch (Exception e) {
....
}
configureApp returns an instance of SpringApplicationBuilder with all the necessary configurations. .run(args) is then called upon this builder.
Here, I am interested not in displaying the exceptions to the user, simply how to properly catch them.
Aucun commentaire:
Enregistrer un commentaire