本人前期开发的项目以Web项目为主,后期开发的一些小程序也都是开发成Web项目,这样服务器端口占用过多,看着很不舒服也浪费资源
首先新建一个springboot非Web工程,修改启动项部分如下:
@SpringBootApplication
@EnableScheduling
public class HssAuditApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(HssAuditApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
Thread.currentThread().join();
}
}
这里利用了 SpringBoot 提供的 CommandLineRunner 特性
通过 Thread.currentThread().join() 使得应用程序在执行run方法时阻塞, 这样程序就可以保持运行,项目触发主要是以定时任务的形式进行的