Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加spring-boot-starter模块,简化springboot项目中的配置 #3392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<!-- xxl-job-core -->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<artifactId>xxl-job-spring-boot-starter</artifactId>
<version>${project.parent.version}</version>
</dependency>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ logging.config=classpath:logback.xml


### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
xxl.job.admin-address=http://127.0.0.1:8080/xxl-job-admin

### xxl-job, access token
xxl.job.accessToken=default_token
xxl.job.access-token=default_token

### xxl-job executor appname
xxl.job.executor.appname=xxl-job-executor-sample
xxl.job.app-name=xxl-job-executor-sample
### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
xxl.job.executor.address=
xxl.job.address=
### xxl-job executor server-info
xxl.job.executor.ip=
xxl.job.executor.port=9999
xxl.job.ip=
xxl.job.port=9999
### xxl-job executor log-path
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
xxl.job.log-path=/data/applogs/xxl-job/jobhandler
### xxl-job executor log-retention-days
xxl.job.executor.logretentiondays=30
xxl.job.log-retention-days=30
69 changes: 69 additions & 0 deletions xxl-job-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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>2.4.1-SNAPSHOT</version>
</parent>
<artifactId>xxl-job-spring-boot-starter</artifactId>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
<description>xxl-job-spring-boot-starter</description>
<url>https://www.xuxueli.com/</url>

<properties>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot (依赖管理:继承一些默认的依赖,工程需要依赖的jar包的管理,申明其他dependency的时候就不需要version) -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- xxl-job-core -->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>${project.parent.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.xxl.job.autoconfigure;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
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;

/**
* @author linyunlong
*/
@Configuration
@EnableConfigurationProperties(XxlJobProperties.class)
@ConditionalOnProperty(value = "xxl.job.enabled", havingValue = "true", matchIfMissing = true)
public class XxlJobAutoConfiguration {
@ConditionalOnMissingBean(XxlJobSpringExecutor.class)
@Bean
public XxlJobSpringExecutor xxlJobSpringExecutor(XxlJobProperties properties) {
XxlJobSpringExecutor executor = new XxlJobSpringExecutor();
executor.setAdminAddresses(properties.getAdminAddress());
executor.setAccessToken(properties.getAccessToken());

executor.setAppname(properties.getAppName());
executor.setAddress(properties.getAddress());
executor.setIp(properties.getIp());
executor.setPort(properties.getPort());
executor.setLogPath(properties.getLogPath());
executor.setLogRetentionDays(properties.getLogRetentionDays());

return executor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.xxl.job.autoconfigure;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* @author linyunlong
*/
@ConfigurationProperties("xxl.job")
@Data
@Slf4j
public class XxlJobProperties {
/**
* xxl-job后台地址
*/
private String adminAddress;
/**
* accessToken,与xxl-job后台配置保持一致
*/
private String accessToken;
/**
* 本执行器名称
*/
private String appName;
/**
* 本执行器地址
*/
private String address;
/**
* 本执行器IP
*/
private String ip;
/**
* 本执行器端口
*/
private int port;
/**
* 日志路径
*/
private String logPath;
/**
* 日志存储天数
*/
private int logRetentionDays = 7;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.xxl.job.autoconfigure.XxlJobAutoConfiguration