Spring Boot 为我们提供了一个方法,通过实现接口 CommandLineRunner 来实现。
@SpringBootApplication
public class DemoApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
public void run(String... strings) throws Exception {
//可以进行TCP Server的启动
System.out.println("执行所需任务,或加载资源");
}
}
该博客介绍了如何在SpringBoot应用中实现CommandLineRunner接口,以在程序启动时执行特定任务,例如启动TCP服务器。通过覆盖run方法,可以在其中添加自定义的初始化逻辑或资源加载操作。
843

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



