org.zodiac.autoconfigure.scc.client.SpringCloudClientBootstrapConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.scc.client;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnSpringCloudBootstrapDisabled;
import org.zodiac.autoconfigure.bootstrap.config.client.HttpAppConfigClientProperties;
import org.zodiac.autoconfigure.scc.client.condition.ConditionalOnSpringCloudAppConfigClientEnabled;
import org.zodiac.scc.client.SpringCloudConfigPropertySourceLocator;
@SpringBootConfiguration
@ConditionalOnSpringCloudBootstrapDisabled
@ConditionalOnSpringCloudAppConfigClientEnabled
public class SpringCloudClientBootstrapConfiguration {
private Environment environment;
private HttpAppConfigClientProperties httpAppConfigClientProperties;
public SpringCloudClientBootstrapConfiguration(Environment environment,
ObjectProvider httpAppConfigClientProperties) {
this.environment = environment;
this.httpAppConfigClientProperties = httpAppConfigClientProperties.getIfAvailable();
}
@Bean
@ConfigurationProperties(prefix = org.zodiac.scc.client.constants.SpringConfigClientSystemPropertiesConstants.SPRING_BOOTSTRAP_CONFIG_SPRING_CLOUD_PREFIX, ignoreInvalidFields = true)
protected SpringCloudAppConfigClientProperties springCloudAppConfigClientProperties() {
SpringCloudAppConfigClientProperties properties = new SpringCloudAppConfigClientProperties(environment);
if (null != httpAppConfigClientProperties)
BeanUtils.copyProperties(httpAppConfigClientProperties, properties);
return properties;
}
@Bean
@ConditionalOnMissingBean
protected SpringCloudConfigPropertySourceLocator configServicePropertySource(
SpringCloudAppConfigClientProperties springCloudAppConfigClientProperties) {
SpringCloudConfigPropertySourceLocator locator = new SpringCloudConfigPropertySourceLocator(
springCloudAppConfigClientProperties);
return locator;
}
}