xxl-job的springboot项目的执行器demo
时间: 2023-07-21 22:54:43 浏览: 115
好的,我可以为你提供一个简单的xxl-job的SpringBoot项目执行器demo。具体步骤如下:
1. 首先,你需要在pom.xml中添加xxl-job的依赖:
```xml
<dependency>
<groupId>com.xxl-job</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.2.1</version>
</dependency>
```
2. 然后,你需要在application.properties中配置xxl-job的相关参数:
```properties
# xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
xxl.job.admin.addresses=http://localhost:8080/xxl-job-admin
# executor registry name, must be unique
xxl.job.executor.appname=executor-demo
# executor ip
xxl.job.executor.ip=127.0.0.1
# executor port
xxl.job.executor.port=9999
# executor log path
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
# executor log retention days
xxl.job.executor.logretentiondays=30
```
3. 接下来,你需要编写一个继承自IJobHandler接口的具体任务处理类,例如:
```java
@Component
public class DemoJobHandler extends IJobHandler {
@Override
public ReturnT<String> execute(String param) throws Exception {
System.out.println("Hello, xxl-job!");
return ReturnT.SUCCESS;
}
}
```
4. 最后,你需要在SpringBoot的启动类中添加@EnableXxlJob注解,以启用xxl-job:
```java
@SpringBootApplication
@EnableXxlJob
public class ExecutorDemoApplication {
public static void main(String[] args) {
SpringApplication.run(ExecutorDemoApplication.class, args);
}
}
```
现在,你就可以在xxl-job的管理页面上创建一个新的任务,并选择刚才编写的执行器demo进行测试了。
阅读全文