`@EnableScheduling` 是Spring框架中的一个注解,它用于开启基于注解的任务调度支持。当你在你的Spring应用程序中使用这个注解时,它允许你通过`@Scheduled`注解来配置和执行定时任务。
以下是如何使用 `@EnableScheduling` 的基本步骤:
1. **添加@EnableScheduling注解**:
在你的Spring Boot启动类或者配置类上添加`@EnableScheduling`注解,以开启定时任务的支持。
```java
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableScheduling
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
```
2. **创建定时任务方法**:
在你的组件中创建方法,并使用`@Scheduled`注解来配置任务的执行计划。
`&#