chatGPT帮你写代码:
提问问题:xxljob在springboot项目中的使用方法,使用注解
回答如下:
1、在pom.xml中添加xxl-job依赖
<dependency> <groupId>com.xuxueli</groupId> <artifactId>xxl-job-core</artifactId> <version>2.2.0</version> </dependency>
2、在springboot的启动类中添加@EnableXxlJob注解
@EnableXxlJob @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
3、在application.yml中配置xxl-job的相关参数
xxl:
job:
admin:
address: http://127.0.0.1:8080
accessToken:
executor:
appname: my-job-executor
address: 127.0.0.1:9999
ip:
port:
logpath: /data/applogs/xxl-job/jobhandler
logretentiondays: 30
4、在需要调度的类上添加@XxlJob注解
@XxlJob("demoJobHandler") @Component public class DemoJobHandler extends IJobHandler { @Override public ReturnT<String> execute(String param) throws Exception { XxlJobLogger.log("XXL-JOB, Hello World."); return SUCCESS; } }