在Springboot启动后执行代码 Springboot启动后执行代码 Springboot启动后执行代码 有时候我们需要在Springboot启动后就执行一些代码,这时候可以通过写一个类实现CommandLineRunner接口,然后在该类上加上@Component注解就可以了。代码如下: @Component public class AfterStartDo implements CommandLineRunner { @Override public void run(String... args) throws Exception { System.out.println("do this...."); } }