mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-23 05:00:23 +08:00
✨ pig-common-job Remove class scanning
This commit is contained in:
parent
7def0d11b2
commit
cc1253fa74
@ -1,16 +1,18 @@
|
||||
package com.pig4cloud.pig.common.job;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.pig4cloud.pig.common.job.properties.XxlExecutorProperties;
|
||||
import com.pig4cloud.pig.common.job.properties.XxlJobProperties;
|
||||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* xxl-job自动装配
|
||||
*
|
||||
@ -19,7 +21,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan("com.pig4cloud.pig.common.job.properties")
|
||||
@EnableConfigurationProperties(XxlJobProperties.class)
|
||||
public class XxlJobAutoConfiguration {
|
||||
|
||||
/**
|
||||
@ -34,16 +36,22 @@ public class XxlJobAutoConfiguration {
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public XxlJobSpringExecutor xxlJobSpringExecutor(XxlJobProperties xxlJobProperties,
|
||||
public XxlJobSpringExecutor xxlJobSpringExecutor(XxlJobProperties xxlJobProperties, Environment environment,
|
||||
DiscoveryClient discoveryClient) {
|
||||
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||
xxlJobSpringExecutor.setAppname(xxlJobProperties.getExecutor().getAppname());
|
||||
xxlJobSpringExecutor.setAddress(xxlJobProperties.getExecutor().getAddress());
|
||||
xxlJobSpringExecutor.setIp(xxlJobProperties.getExecutor().getIp());
|
||||
xxlJobSpringExecutor.setPort(xxlJobProperties.getExecutor().getPort());
|
||||
xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getExecutor().getAccessToken());
|
||||
xxlJobSpringExecutor.setLogPath(xxlJobProperties.getExecutor().getLogPath());
|
||||
xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getExecutor().getLogRetentionDays());
|
||||
XxlExecutorProperties executor = xxlJobProperties.getExecutor();
|
||||
// 应用名默认为服务名
|
||||
String appName = executor.getAppname();
|
||||
if (!StringUtils.hasText(appName)) {
|
||||
appName = environment.getProperty("spring.application.name");
|
||||
}
|
||||
xxlJobSpringExecutor.setAppname(appName);
|
||||
xxlJobSpringExecutor.setAddress(executor.getAddress());
|
||||
xxlJobSpringExecutor.setIp(executor.getIp());
|
||||
xxlJobSpringExecutor.setPort(executor.getPort());
|
||||
xxlJobSpringExecutor.setAccessToken(executor.getAccessToken());
|
||||
xxlJobSpringExecutor.setLogPath(executor.getLogPath());
|
||||
xxlJobSpringExecutor.setLogRetentionDays(executor.getLogRetentionDays());
|
||||
|
||||
// 如果配置为空则获取注册中心的服务列表 "http://pigx-xxl:9080/xxl-job-admin"
|
||||
if (!StringUtils.hasText(xxlJobProperties.getAdmin().getAddresses())) {
|
||||
|
@ -1,12 +1,8 @@
|
||||
package com.pig4cloud.pig.common.job.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
|
||||
/**
|
||||
* xxl-job配置
|
||||
@ -15,30 +11,13 @@ import org.springframework.util.StringUtils;
|
||||
* @date 2020/9/14
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "xxl.job")
|
||||
public class XxlJobProperties implements InitializingBean, EnvironmentAware {
|
||||
|
||||
private Environment environment;
|
||||
public class XxlJobProperties {
|
||||
|
||||
@NestedConfigurationProperty
|
||||
private XxlAdminProperties admin = new XxlAdminProperties();
|
||||
|
||||
@NestedConfigurationProperty
|
||||
private XxlExecutorProperties executor = new XxlExecutorProperties();
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
// 若是没有设置appname 则取 application Name
|
||||
if (!StringUtils.hasText(executor.getAppname())) {
|
||||
executor.setAppname(environment.getProperty("spring.application.name"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@code Environment} that this component runs in.
|
||||
*/
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user