需要在容器启动的时候完成后做一些事情
springboot有两个接口可以实现。这两个接口分别为CommandLineRunner和ApplicationRunner。他们的执行时间为容器启动完成的时候。实现run方法就可以。目前使用到的是ApplicationRunner
@Component
public class MyRunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("测试ApplicationRunner接口");
}
}
本文介绍了如何在Spring Boot应用中使用ApplicationRunner接口,以确保在容器启动完成后执行特定操作。通过实现run方法并配置@Component,MyRunner类展示了如何在启动时打印测试信息。
278

被折叠的 条评论
为什么被折叠?



