原因
@Scheduled(cron = "0/5 * * * * ?")//注解标识的是静态方法,必须用static修饰
public static void xxxx(){}
引申出的问题,如何调用非静态DAO方法(因为没有业务逻辑,所以直接调用dao)
在启动类中加入静态配置变量
@SpringBootApplication
@EnableScheduling
public class CloudEmrApplication {
public static ConfigurableApplicationContext ac;
public static void main(String[] args) {
CloudEmrApplication.ac = SpringApplication.run(CloudEmrApplication.class, args);
}
}
在调度任务中直接调用
@Component
public class xxxxController {
@Scheduled(cron = "0/5 * * * * ?")
public static void xxxx() {
try {
xxxx bean = CloudEmrApplication.ac.getBean(xxxx.class);
List<xxxx> entityList = bean.xxxx(xxxx);
} catch (Exception e) {
e.printStackTrace();
}
}
}