diff --git a/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/XxlJobAutoConfiguration.java b/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/XxlJobAutoConfiguration.java index a8eb2894f..5d57fe384 100644 --- a/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/XxlJobAutoConfiguration.java +++ b/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/XxlJobAutoConfiguration.java @@ -1,22 +1,7 @@ -/* - * Copyright (c) 2018-2025, lengleng All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the pig4cloud.com developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: lengleng (wangiegie@gmail.com) - */ - package com.pig4cloud.pigx.common.job; +import java.util.stream.Collectors; + import com.pig4cloud.pigx.common.job.properties.XxlJobProperties; import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -26,15 +11,13 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; -import java.util.stream.Collectors; - /** - * @author lengleng - * @date 2020-11-09 - *
- * xxl 初始化 + * xxl-job自动装配 + * + * @author lishangbu + * @date 2020/9/14 */ -@Configuration +@Configuration(proxyBeanMethods = false) @EnableAutoConfiguration @ComponentScan("com.pig4cloud.pigx.common.job.properties") public class XxlJobAutoConfiguration { @@ -63,7 +46,7 @@ public class XxlJobAutoConfiguration { xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getExecutor().getLogRetentionDays()); // 如果配置为空则获取注册中心的服务列表 "http://pigx-xxl:9080/xxl-job-admin" - if (StringUtils.isEmpty(xxlJobProperties.getAdmin().getAddresses())) { + if (!StringUtils.hasText(xxlJobProperties.getAdmin().getAddresses())) { String serverList = discoveryClient.getServices().stream().filter(s -> s.contains(XXL_JOB_ADMIN)) .flatMap(s -> discoveryClient.getInstances(s).stream()).map(instance -> String .format("http://%s:%s/%s", instance.getHost(), instance.getPort(), XXL_JOB_ADMIN)) diff --git a/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlAdminProperties.java b/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlAdminProperties.java index 6155a1b6d..c5ffc3567 100644 --- a/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlAdminProperties.java +++ b/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlAdminProperties.java @@ -1,29 +1,12 @@ -/* - * Copyright (c) 2018-2025, lengleng All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the pig4cloud.com developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: lengleng (wangiegie@gmail.com) - */ - package com.pig4cloud.pigx.common.job.properties; import lombok.Data; /** - * @author lengleng - * @date 2019-09-18 - *
- * xxl 管控台相关属性 + * xxl-job管理平台配置 + * + * @author lishangbu + * @date 2020/9/14 */ @Data public class XxlAdminProperties { diff --git a/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlExecutorProperties.java b/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlExecutorProperties.java index aa7172c10..cb3824e45 100644 --- a/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlExecutorProperties.java +++ b/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlExecutorProperties.java @@ -1,27 +1,12 @@ -/* - * Copyright (c) 2018-2025, lengleng All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the pig4cloud.com developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: lengleng (wangiegie@gmail.com) - */ - package com.pig4cloud.pigx.common.job.properties; import lombok.Data; /** - * @author lengleng - * @date 2019-09-18 + * xxl-job执行器配置 + * + * @author lishangbu + * @date 2020/9/14 */ @Data public class XxlExecutorProperties { @@ -29,7 +14,7 @@ public class XxlExecutorProperties { /** * 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册 */ - private String appname = "xxl-job-executor"; + private String appname; /** * 服务注册地址,优先使用该配置作为注册地址 为空时使用内嵌服务 ”IP:PORT“ 作为注册地址 从而更灵活的支持容器类型执行器动态IP和动态映射端口问题 diff --git a/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlJobProperties.java b/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlJobProperties.java index 87b84b1da..4a0eda184 100644 --- a/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlJobProperties.java +++ b/pigx-common/pigx-common-job/src/main/java/com/pig4cloud/pigx/common/job/properties/XxlJobProperties.java @@ -1,37 +1,44 @@ -/* - * Copyright (c) 2018-2025, lengleng All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the pig4cloud.com developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: lengleng (wangiegie@gmail.com) - */ - package com.pig4cloud.pigx.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; /** - * @author lengleng - * @date 2019-09-18 + * xxl-job配置 + * + * @author lishangbu + * @date 2020/9/14 */ @Data @Component @ConfigurationProperties(prefix = "xxl.job") -public class XxlJobProperties { +public class XxlJobProperties implements InitializingBean, EnvironmentAware { + + private Environment environment; private XxlAdminProperties admin = new XxlAdminProperties(); private XxlExecutorProperties executor = new XxlExecutorProperties(); -} \ No newline at end of file + @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; + } + +}