项目引入xxljob,仅需要导入对应的starter包,即可进行快速开发
- <dependency>
- <groupId>com.ydlgroupId>
- <artifactId>xxl-job-spring-boot-starterartifactId>
- <version>0.0.1-SNAPSHOTversion>
- dependency>
目录结构:

pom.xml中仅导入对应的xxl-job-spring-boot-autoconfiguration依赖
- "1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <artifactId>xxl-job-starterartifactId>
- <groupId>com.xiaozhengroupId>
- <version>0.0.1-SNAPSHOTversion>
- parent>
- <modelVersion>4.0.0modelVersion>
-
- <artifactId>xxl-job-spring-boot-starterartifactId>
- <dependencies>
- <dependency>
- <groupId>com.ydlgroupId>
- <artifactId>xxl-job-spring-boot-autoconfigurationartifactId>
- <version>0.0.1-SNAPSHOTversion>
- dependency>
- dependencies>
-
- project>
pom.properties
- version=0.0.1-SNAPSHOT
- groupId=com.xiaozhen
- artifactId=xxl-job-spring-boot-starter
目录文件
xxlJobAutoConfiguration为配置类,springBoot启动时会加重
- /**
- * 注解解释:
- *
- * @Configuration //指定这个类是一个配置类
- * @ConditionalOnXXX //在指定条件成立的情况下自动配置类生效
- * @AutoConfigureAfter //指定自动配置类的顺序
- * @Bean //给容器中添加组件
- * @ConfigurationPropertie结合相关xxxProperties类来绑定相关的配置
- * @EnableConfigurationProperties //让xxxProperties生效加入到容器中
- */
- @Component
- @EnableConfigurationProperties({XxlJobProperties.class})
- public class XxlJobAutoConfiguration {
- private static Logger logger = LoggerFactory.getLogger(XxlJobAutoConfiguration.class);
- @Resource
- private XxlJobProperties xxlJobProperties;
-
- public XxlJobAutoConfiguration() {
- }
-
- /**
- * 配置信息
- **/
- @Bean
- public XxlJobSpringExecutor xxlJobExecutor() {
- logger.info(">>>>>>>>>>> xxl-job config init.");
- XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
- xxlJobSpringExecutor.setAdminAddresses(this.xxlJobProperties.getAdminAddresses());
- xxlJobSpringExecutor.setAppName(this.xxlJobProperties.getExecutorAppName());
- xxlJobSpringExecutor.setIp(this.xxlJobProperties.getExecutorIp());
- xxlJobSpringExecutor.setPort(this.xxlJobProperties.getExecutorPort());
- xxlJobSpringExecutor.setAccessToken(this.xxlJobProperties.getAccessToken());
- xxlJobSpringExecutor.setLogPath(this.xxlJobProperties.getExecutorLogPath() + this.xxlJobProperties.getExecutorAppName());
- xxlJobSpringExecutor.setLogRetentionDays(this.xxlJobProperties.getExecutorLogRetentionDays());
- return xxlJobSpringExecutor;
- }
- }
xxlJobProperties
- @ConfigurationProperties(
- prefix = "xxl.job"
- )
- public class XxlJobProperties {
- private String adminAddresses = "http://localhost:8093/xxl-job-admin";
- private String accessToken;
- private String executorAppName = "xxl-job-executor-default";
- private String executorIp;
- private int executorPort = 9999;
- private String executorLogPath = "/data/applogs/xxl-job/jobhandler/";
- private int executorLogRetentionDays = 30;
-
- public XxlJobProperties() {
- }
- }
pom.xml导入相关的jar包
- "1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0modelVersion>
- <parent>
- <artifactId>xxl-job-starterartifactId>
- <groupId>com.xiaozhengroupId>
- <version>0.0.1-SNAPSHOTversion>
- parent>
- <groupId>com.ydlgroupId>
- <artifactId>xxl-job-spring-boot-autoconfigurationartifactId>
- <version>0.0.1-SNAPSHOTversion>
- <name>xxl-job-spring-boot-autoconfigurationname>
- <description>Demo project for Spring Bootdescription>
-
- <properties>
- <java.version>1.8java.version>
- properties>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starterartifactId>
- dependency>
-
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-configuration-processorartifactId>
- <optional>trueoptional>
- dependency>
- <dependency>
- <groupId>org.projectlombokgroupId>
- <artifactId>lombokartifactId>
- <optional>trueoptional>
- dependency>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-testartifactId>
- <scope>testscope>
- <exclusions>
- <exclusion>
- <groupId>org.junit.vintagegroupId>
- <artifactId>junit-vintage-engineartifactId>
- exclusion>
- exclusions>
- dependency>
-
-
- <dependency>
- <groupId>com.xuxueligroupId>
- <artifactId>xxl-job-coreartifactId>
- <version>2.1.1version>
- dependency>
- dependencies>
- project>
spring.factories文件(spring启动的时候会加载此文件中的配置类)
- org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
- com.ydl.xxljobspringbootautoconfiguration.XxlJobAutoConfiguration
- org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
- com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration
-
-
- org.springframework.context.ApplicationListener=\
- com.alibaba.boot.dubbo.context.event.OverrideDubboConfigApplicationListener,\
- com.alibaba.boot.dubbo.context.event.WelcomeLogoApplicationListener,\
- com.alibaba.boot.dubbo.context.event.AwaitingNonWebApplicationListener

- public class AwaitingNonWebApplicationListener implements ApplicationListener
{ -
- @Order //最低优先级确保最后执行
- public class OverrideDubboConfigApplicationListener implements ApplicationListener
{ -
-
- @Order(LoggingApplicationListener.DEFAULT_ORDER + 1)
- public class WelcomeLogoApplicationListener implements ApplicationListener
{