All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.xxljob.XxlJobAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.xxljob;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;

@SpringBootConfiguration
@ConditionalOnClass(name = {"org.zodiac.xxljob.handler.SampleXxlJob", "com.xxl.job.core.executor.XxlJobExecutor"})
@ConditionalOnProperty(name = org.zodiac.xxljob.constants.XxlJobSystemPropertiesConstants.XXL_JOB_ENABLED, havingValue = "true")
public class XxlJobAutoConfiguration {

    private static Logger log = LoggerFactory.getLogger(XxlJobAutoConfiguration.class);

    public XxlJobAutoConfiguration() {
    }

    @Bean
    @ConfigurationProperties(prefix = org.zodiac.xxljob.constants.XxlJobSystemPropertiesConstants.XXL_JOB_PREFIX)
    protected XxlJobProperties xxlJobProperties() {
        return new XxlJobProperties();
    }

    @Bean
    @ConditionalOnMissingBean
    protected XxlJobSpringExecutor xxlJobExecutor( XxlJobProperties xxlJobProperties) {
        log.info(">>>>>>>>>>> xxl-job config init.");
        log.info(">>>> ip="+xxlJobProperties.getIp()+",Port="+xxlJobProperties.getPort()+",address="+xxlJobProperties.getAdminAddresses());
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());
        xxlJobSpringExecutor.setAppname(xxlJobProperties.getAppname());
        //update-begin--Author:scott -- Date:20210305 -- for:system服务和demo服务有办法同时使用xxl-job吗 #2313---
        xxlJobSpringExecutor.setIp(xxlJobProperties.getIp());
        xxlJobSpringExecutor.setPort(xxlJobProperties.getPort());
        //update-end--Author:scott -- Date:20210305 -- for:system服务和demo服务有办法同时使用xxl-job吗 #2313---
        xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());
        xxlJobSpringExecutor.setLogPath(xxlJobProperties.getLogPath());
        xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getLogRetentionDays());
        return xxlJobSpringExecutor;
    }

    /**
     * SpringCloud环境中针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
     *
     *      1、引入依赖:
     *          
     *             org.springframework.cloud
     *             spring-cloud-commons
     *             ${version}
     *         
     *
     *      2、配置文件,或者容器启动变量
     *          spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
     *
     *      3、获取IP
     *          String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
     */

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy