Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<module>xxl-job-core</module>
<module>xxl-job-admin</module>
<module>xxl-job-executor-samples</module>
<module>xxl-job-spring-boot-starter</module>
</modules>

<properties>
Expand Down Expand Up @@ -136,7 +137,7 @@
</execution>
</executions>
</plugin>
<!-- maven central -->
<!-- maven central -->
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
Expand Down
35 changes: 35 additions & 0 deletions xxl-job-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job</artifactId>
<version>3.2.1-SNAPSHOT</version>
</parent>

<groupId>com.xxl.job</groupId>
<artifactId>xxl-job-spring-boot-starter</artifactId>
<version>3.2.1-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>3.5.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>3.2.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package com.xxl.job.spring.boot.autoconfigure;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "xxl.job")
public class XxlJobProperties {
private boolean enabled;

private Admin admin;

private String accessToken;

private Executor executor;

public static class Admin {
private String addresses; // xxl.job.admin.addresses

public Admin() {
}

public Admin(String addresses) {
this.addresses = addresses;
}

public String getAddresses() {
return addresses;
}

public void setAddresses(String addresses) {
this.addresses = addresses;
}
}

public static class Executor {
private String appname; // xxl.job.executor.app-name
private String address;
private String ip;
private Integer port;
private String logPath;
private int logretentiondays;


public Executor() {
}

public Executor(String appname, String address, String ip, Integer port, String logPath, int logretentiondays) {
this.appname = appname;
this.address = address;
this.ip = ip;
this.port = port;
this.logPath = logPath;
this.logretentiondays = logretentiondays;
}

public String getAppname() {
return appname;
}

public void setAppname(String appname) {
this.appname = appname;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public Integer getPort() {
return port;
}

public void setPort(Integer port) {
this.port = port;
}

public String getLogPath() {
return logPath;
}

public void setLogPath(String logPath) {
this.logPath = logPath;
}

public int getLogretentiondays() {
return logretentiondays;
}

public void setLogretentiondays(int logretentiondays) {
this.logretentiondays = logretentiondays;
}
}

public XxlJobProperties() {
}


public XxlJobProperties(boolean enabled, Admin admin, String accessToken, Executor executor) {
this.enabled = enabled;
this.admin = admin;
this.accessToken = accessToken;
this.executor = executor;
}

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public Admin getAdmin() {
return admin;
}

public void setAdmin(Admin admin) {
this.admin = admin;
}

public String getAccessToken() {
return accessToken;
}

public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}

public Executor getExecutor() {
return executor;
}

public void setExecutor(Executor executor) {
this.executor = executor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.xxl.job.spring.boot.autoconfigure;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Objects;

@Configuration
@ConditionalOnClass({XxlJobSpringExecutor.class})
@EnableConfigurationProperties(XxlJobProperties.class)
@ConditionalOnProperty(name = "xxl.job.executor.enabled")
public class XxlJobSpringBootAutoConfiguration {
private final XxlJobProperties xxlJobProperties;
private Logger logger = LoggerFactory.getLogger(XxlJobSpringBootAutoConfiguration.class);

public XxlJobSpringBootAutoConfiguration(XxlJobProperties xxlJobProperties) {
this.xxlJobProperties = xxlJobProperties;
}

@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
logger.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdmin().getAddresses());
xxlJobSpringExecutor.setAppname(xxlJobProperties.getExecutor().getAppname());
if (Objects.nonNull(xxlJobProperties.getExecutor().getAddress()) && !xxlJobProperties.getExecutor().getAddress().isEmpty()) {
xxlJobSpringExecutor.setAddress(xxlJobProperties.getExecutor().getAddress());
}
if (Objects.nonNull(xxlJobProperties.getExecutor().getIp()) && !xxlJobProperties.getExecutor().getIp().isEmpty()) {
xxlJobSpringExecutor.setIp(xxlJobProperties.getExecutor().getIp());
}
if (Objects.nonNull(xxlJobProperties.getExecutor().getPort()) && xxlJobProperties.getExecutor().getPort() > 0) {
xxlJobSpringExecutor.setPort(xxlJobProperties.getExecutor().getPort());
}
xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());
xxlJobSpringExecutor.setLogPath(xxlJobProperties.getExecutor().getLogPath());
xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getExecutor().getLogretentiondays());
return xxlJobSpringExecutor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"groups": [
{
"name": "xxl.job.enabled",
"type": "java.lang.Boolean",
"description": "xxl job enabled",
"defaultValue": false,
"sourceType": "com.xxl.job.spring.boot.autoconfigure.XxlJobProperties",
"sourceMethod": "isEnabled"
},
{
"name": "xxl.job.admin.addresses",
"type": "java.lang.String",
"description": "xxl job admin addresses",
"defaultValue": "http://localhost:8080/xxl-job-admin",
"sourceType": "com.xxl.job.spring.boot.autoconfigure.XxlJobProperties$Admin",
"sourceMethod": "getAddresses"
},
{
"name": "xxl.job.accessToken",
"type": "java.lang.String",
"description": "xxl job access token",
"defaultValue": "defaultToken",
"sourceType": "com.xxl.job.spring.boot.autoconfigure.XxlJobProperties",
"sourceMethod": "getAccessToken"
},
{
"name": "xxl.job.executor.appname",
"type": "java.lang.String",
"description": "xxl job executor app name",
"defaultValue": "",
"sourceType": "com.xxl.job.spring.boot.autoconfigure.XxlJobProperties$Executor",
"sourceMethod": "getAppname"
},
{
"name": "xxl.job.executor.address",
"type": "java.lang.String",
"description": "xxl job executor address",
"defaultValue": "",
"sourceType": "com.xxl.job.spring.boot.autoconfigure.XxlJobProperties$Executor",
"sourceMethod": "getAddress"
},
{
"name": "xxl.job.executor.ip",
"type": "java.lang.String",
"description": "xxl job executor ip",
"defaultValue": "",
"sourceType": "com.xxl.job.spring.boot.autoconfigure.XxlJobProperties$Executor",
"sourceMethod": "getIp"
},
{
"name": "xxl.job.executor.port",
"type": "java.lang.Integer",
"description": "xxl job executor port",
"defaultValue": 0,
"sourceType": "com.xxl.job.spring.boot.autoconfigure.XxlJobProperties$Executor",
"sourceMethod": "getPort"
},
{
"name": "xxl.job.executor.logPath",
"type": "java.lang.String",
"description": "xxl job executor log path",
"defaultValue": "",
"sourceType": "com.xxl.job.spring.boot.autoconfigure.XxlJobProperties$Executor",
"sourceMethod": "getLogPath"
},
{
"name": "xxl.job.executor.logretentiondays",
"type": "java.lang.Integer",
"description": "xxl job executor log retention days",
"defaultValue": 0,
"sourceType": "com.xxl.job.spring.boot.autoconfigure.XxlJobProperties$Executor",
"sourceMethod": "getLogretentiondays"
}
],
"hints": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.xxl.job.spring.boot.autoconfigure.XxlJobSpringBootAutoConfiguration