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

top.yonyong.yconfig.config.ConfigContextAutoConfig Maven / Gradle / Ivy

There is a newer version: 1.1.0.RELEASE
Show newest version
package top.yonyong.yconfig.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
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.Configuration;
import org.springframework.context.annotation.Scope;
import top.yonyong.yconfig.utils.StringUtils;

/**
 * @author  yonyong
 **/
@Configuration
@ConditionalOnClass(ConfigContext.class)
public class ConfigContextAutoConfig {

    @Value("${config.center.group:DEFAULT_ENV}")
    private String group;

    @Bean(name = "applicationConfigContext")
    @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
    @ConditionalOnMissingBean(ConfigContext.class)
    public ConfigContext myConfigContext() {
        ConfigContext configContext = ConfigContext.builder().build();
        //set group
        if (StringUtils.isBlank(group))
            group = "DEFAULT_ENV";
        //set vals
        configContext = configContext.toBuilder()
                .group(group)
                .build();
        return configContext;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy