使用Spring Boot 的CommandLineRunner遇到的坑
启动时失败
原因
CommandLineRunner的run方法是单线程执行的,当存在时间过长或多个线程执行时,有可能遇到阻塞会停止
解决办法
开启新的线程进行执行
@Component
public class ScheduleJobInitListener implements CommandLineRunner {
@Autowired
TaskService scheduleJobService;
@Override
public void run(String... arg0) throws Exception {
new Thread() {
public void run() {
try {
scheduleJobService.initSchedule();
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
}
执行成功,打包失败,显示JdbcSQLException: not found table ‘XXX’
经过网上的搜查,显示提示这个错误的原因是字段写错,或大小写异常。但与碰到的问题不一样。我进行了如下筛查:
- 先行确认代码是否存在编写错误ÿ