springboot自定义启动类
程序员文章站
2022-05-29 17:14:13
...
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)
我启动了
这里只是做了简单的输出,可根据自己的需求进行相应的逻辑添加