Start the execution method:
Implement the run method in the ApplicationRunner interface .
If there are multiple implementation classes and you need them to be executed in a certain order, you can add the @Order annotation to the implementation class. @Order(value=integer value). SpringBoot will execute in order from small to large according to the value in @Order.
close execution method
One is to implement the DisposableBean interface, and the other is to use the @PreDestroy annotation.
- @Component
- publicclass TestImplDisposableBean implements DisposableBean, ExitCodeGenerator {
- @Override
- publicvoid destroy() throws Exception {
- System.out.println("<<<<<<<<<<<我被销毁了......................>>>>>>>>>>>>>>>");
- System.out.println("<<<<<<<<<<<我被销毁了......................>>>>>>>>>>>>>>>");
- }
- @Override
- public int getExitCode() {
- return5;
- }
- }
- @Component
- public class TestAnnotationPreDestroy {
- @PreDestroy
- publicvoid destory() {
- System.out.println( "I was destroyed,,,,,I used @PreDestory method,,,,,,," );
- System.out.println( "I was destroyed,,,,,I used @PreDestory method,,,,,,," );
- }
- }