SpringBoot 任务调度
时间: 2023-10-05 21:11:54 浏览: 126
SpringBoot任务调度可以通过在启动类上标注@EnableScheduling来开启。具体的步骤如下:
1. 在启动类上标注@EnableScheduling注解,以开启定时任务。例如:
```java
@SpringBootApplication
@EnableScheduling
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
```
2. 在pom.xml文件中添加相关的依赖。例如,可以使用以下依赖:
```xml
<!-- spring-boot-starter-web (spring-webmvc tomcat) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- xxl-job-core 版本号根据自己下载的版本修改 -->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.1.1-SNAPSHOT</version>
</dependency>
```
3. 可以使用@ConfigurationProperties、@PropertySource等配置注解来配置相关依赖。例如,可以添加以下依赖:
```xml
<!-- 配置依赖,可以使用@ConfigurationProperties、@PropertySource等配置注解 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.6.4</version>
</dependency>
```
通过以上步骤,你可以在SpringBoot中实现任务调度功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [SpringBoot任务调度](https://blog.csdn.net/weixin_42150397/article/details/123503626)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [springboot的5种任务调度](https://blog.csdn.net/plpldog/article/details/120351267)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文
相关推荐















