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

org.zodiac.autoconfigure.nacos.confcenter.NacosConfCenterBootstrapConfiguration Maven / Gradle / Ivy

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

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.zodiac.autoconfigure.application.ApplicationInfoProperties;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnSpringCloudBootstrapDisabled;
import org.zodiac.autoconfigure.nacos.condition.ConditionalOnNacosConfCenterEnabled;
import org.zodiac.commons.util.Colls;

@SpringBootConfiguration
@ConditionalOnNacosConfCenterEnabled
@ConditionalOnSpringCloudBootstrapDisabled
@org.zodiac.nacos.client.context.annotation.config.EnableNacosConfigClient
@Import(value = {NacosConfCenterBeanDefinitionRegistrar.class})
//@EnableConfigurationProperties(value = {NacosConfCenterProperties.class})
@ConditionalOnMissingBean(name = org.zodiac.nacos.base.constants.NacosBeanConstants.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME)
@ConditionalOnClass(value = {com.alibaba.nacos.api.NacosFactory.class, org.zodiac.nacos.base.NacosAppInstance.class, org.zodiac.nacos.client.context.NacosClientContext.class})
public class NacosConfCenterBootstrapConfiguration {

    private org.zodiac.nacos.client.confcenter.autoconfigure.NacosConfCenterProperties nacosConfCenterProperties;
    private ApplicationInfoProperties applicationInfoProperties;

    public NacosConfCenterBootstrapConfiguration(org.zodiac.nacos.client.confcenter.autoconfigure.NacosConfCenterProperties nacosConfCenterProperties,
        ApplicationInfoProperties applicationInfoProperties) {
        this.nacosConfCenterProperties = nacosConfCenterProperties;
        this.applicationInfoProperties = applicationInfoProperties;
        init();
    }

    @Bean
    @ConditionalOnMissingBean
    protected com.alibaba.nacos.api.config.ConfigService configService() throws com.alibaba.nacos.api.exception.NacosException {
        return com.alibaba.nacos.api.NacosFactory.createConfigService(nacosConfCenterProperties.toNacosConfigProperties());
    }

//    @PostConstruct
    public void init() {
        if (nacosConfCenterProperties.getGroup() == null)
            /*默认使用应用的分组。*/
            nacosConfCenterProperties.setGroup(applicationInfoProperties.getGroup());
        if (Colls.notEmptyColl(nacosConfCenterProperties.getExtConfig())) {
            for (org.zodiac.nacos.base.config.confcenter.NacosConfCenterExtInfo extConfig : nacosConfCenterProperties.getExtConfig()) {
                if (null == extConfig.getGroup())
                    /*默认使用应用的分组。*/
                    extConfig.setGroup(applicationInfoProperties.getGroup());
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy