在低版本的 xxl-job 中, 初始化 XxlJobSpringExecutor 执行器需要在 @Bean 中加上 initMethod = "start", destroyMethod = "destroy",但是在高版本的 xxl-job(如 2.1.2)则需要删除 initMethod = "start", destroyMethod = "destroy"
报错前
@Bean(initMethod = "start", destroyMethod = "destroy")
public XxlJobSpringExecutor xxlJobExecutor() {
log.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(jobProperties.getAdminAddresses());
xxlJobSpringExecutor.setAppName(jobProperties.getAppName());
xxlJobSpringExecutor.setPort(jobProperties.getPort());
xxlJobSpringExecutor.setLogPath(jobProperties.getLogPath());
xxlJobSpringExecutor.setLogRetentionDays(jobProperties.getLogRetentionDays());
xxlJobSpringExecutor.setIp(jobProperties.getIp());
xxlJobSpringExecutor.setAccessToken(jobProperties.getAccessToken());
return xxlJobSpringExecutor;
}
解决
把 @Bean 的属性 initMethod = "start", destroyMethod = "destroy" 删除即可,代码如下:
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
log.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(jobProperties.getAdminAddresses());
xxlJobSpringExecutor.setAppName(jobProperties.getAppName());
xxlJobSpringExecutor.setPort(jobProperties.getPort());
xxlJobSpringExecutor.setLogPath(jobProperties.getLogPath());
xxlJobSpringExecutor.setLogRetentionDays(jobProperties.getLogRetentionDays());
xxlJobSpringExecutor.setIp(jobProperties.getIp());
xxlJobSpringExecutor.setAccessToken(jobProperties.getAccessToken());
return xxlJobSpringExecutor;
}