springboot自定義啟動類
阿新 • • 發佈:2018-12-20
springboot中設定啟動類,其實就是實現了一個介面ApplicationRunner,原始碼如下:
package org.springframework.boot;
@FunctionalInterface
public interface ApplicationRunner {
void run(ApplicationArguments var1) throws Exception;
}
自己的實現類如下:
@Component public class InitConfig implements ApplicationRunner { @Override public void run(ApplicationArguments applicationArguments) throws Exception { /** * 這裡可以新增一些其他邏輯,這裡只是做一個演示,具體是實現了ApplicationRunner */ System.out.println("我啟動了"); } }
啟動專案:
2018-11-30 20:09:25.407 INFO 426428 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2018-11-30 20:09:25.740 INFO 426428 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2018-11-30 20:09:25.984 INFO 426428 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2018-11-30 20:09:25.988 INFO 426428 --- [ main] c.e.demo.SpringbootdemoApplication : Started SpringbootdemoApplication in 4.335 seconds (JVM running for 5.323) 我啟動了
這裡只是做了簡單的輸出,可根據自己的需求進行相應的邏輯新增