org.zodiac.autoconfigure.nacos.confcenter.NacosConfCenterBootstrapConfiguration Maven / Gradle / Ivy
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());
}
}
}
}