@EnableScheduling注解应该加到哪里
时间: 2023-10-17 11:55:23 浏览: 96
@EnableScheduling注解应该加在启动类上,即加在带有@SpringBootApplication注解的类上。在这个类上加上@EnableScheduling注解可以开启定时任务功能。例如:
```java
@SpringBootApplication
@EnableScheduling
public class MainApplication {
public static void main(String\[\] args) {
SpringApplication.run(MainApplication.class, args);
}
}
```
这样就可以在Spring Boot应用中使用定时任务了。\[1\]
#### 引用[.reference_title]
- *1* [SpringBoot中@EnableScheduling注解(定时任务)使用](https://blog.csdn.net/hwj_278347173/article/details/106919371)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [Spring : @EnableScheduling注解 @Scheduled](https://blog.csdn.net/qq_21383435/article/details/103943547)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文