spring-cloud-consul icon indicating copy to clipboard operation
spring-cloud-consul copied to clipboard

add @ConditionalOnMissingBean on ConsulConfigProperties in ConsulConfigBootstrapConfiguration

Open perdonare opened this issue 9 years ago • 11 comments

now I found It's difficult to customerized ConsulConfigProperties

perdonare avatar Nov 20 '17 14:11 perdonare

Can you explain a bit more about what you need?

spencergibb avatar Nov 20 '17 15:11 spencergibb

Typically I have two sets of config for consul where confirm useful for our team and don't need two much config ,and by set the flag I can choose which one we can use , this need dynamic change the consul config , also I want change the config key from spring.cloud.consul.xxx to xxx.consul.xxx

perdonare avatar Nov 21 '17 01:11 perdonare

You can do that with Spring profiles. Why do you need a different prefix?

spencergibb avatar Nov 21 '17 02:11 spencergibb

I want integration cloud consul to our framework , and no need too much care about spring cloud

perdonare avatar Nov 21 '17 02:11 perdonare

That doesn't make much sense to me

spencergibb avatar Nov 21 '17 04:11 spencergibb

any way , it's convenient for other people use

perdonare avatar Nov 21 '17 05:11 perdonare

I don't know. We could have used the class name in @EnableConfigurationProperties instead of @Bean. You'd be in the same situation as now having to use the bean name. We'll never officially support using a different namespace.

spencergibb avatar Nov 21 '17 05:11 spencergibb

I'd like to see if others find it convenient and their reasons

spencergibb avatar Nov 21 '17 05:11 spencergibb

I have a use case where I want to build a thin layer/framework around cloud config and provide a default context and prefix... The overall goal of the wrapper is to provide the software contracts that are required to run a service on our in-house platform such as service discovery and configuration management.

Instead of having all our services define where to look for default properties I would like to have the wrapper set it by providing a ConsulConfigProperties Bean. This would make it easier for the developers to fulfil the contracts that we have within our platform.

I currently did a dirty hack to get a POC working without a conditional bean.

@AutoConfigureBefore(ConsulPropertySourceLocator.class)
public class CloudConfigAutoConfig {
    @Autowired
    private ConsulConfigProperties consulConfigProperties;

    @PostConstruct
    public void init() {
        consulConfigProperties.setPrefix("platform-config");
        consulConfigProperties.setDefaultContext("defaults");
    }

}

edvinerikson avatar May 09 '18 09:05 edvinerikson

PRs welcome

spencergibb avatar May 09 '18 09:05 spencergibb

Awesome @spencergibb! I'll have a look! Though, be aware this will be my first contribution ever to Spring and a JVM open-source project.. :)

edvinerikson avatar May 09 '18 09:05 edvinerikson