Spring-cloud-config: NativeEnvironmentRepository Cannot Be Used In A Composite Configuration

Created on 12 Aug 2019  路  11Comments  路  Source: spring-cloud/spring-cloud-config

It would be useful to add in the documentation that if you want to combine the native profile with another profile, you have to explicitly provide your own NativeEnvironmentRepository bean declaration, otherwise, the auto-configuration backs off and just takes the other profile repository.

documentation feedback-provided help wanted

All 11 comments

Hello, @ask4gilles Thanks for filing this issue. Would you be interested in contributing this bit to Spring Cloud Config documentation?

@OlgaMaciaszek woot!

@ask4gilles can you explain why this doesnt work using a composite environment repository?

@ryanjbaxter It probably would.
My current use case is as follow:

  • use the native and vault profiles for dev env
  • git and vault profiles for other env. (No composite)

Combining native and vault: it just takes the vault repository.
(unless I declare my own NativeRepository bean)
Combining git and vault just works as expected.

Do you suggest it works as expected and that I should always use a composite profile?

See also: https://github.com/spring-cloud/spring-cloud-config/issues/1344#issuecomment-515025118

@ask4gilles in #1344 the user was providing their own EnvironmentRespository bean, so it was a different scenario. If you are just using configuration and using native and vault and/or git and vault it should work fine without the need to provide your own bean

@ryanjbaxter

If you are just using configuration and using native and vault and/or git and vault it should work fine without the need to provide your own bean

It does not seem to be the case... Do you want me to close this PR and create an issue with a minimal example?

No just provide an example here

I forked your sample here https://github.com/ask4gilles/spring-cloud-config-vault and updated the libs to the latest versions. Start the server with native,vault. Put the debug flag on:

NativeRepositoryConfiguration: Did not match: - @ConditionalOnMissingBean (types: org.springframework.cloud.config.server.environment.EnvironmentRepository; SearchStrategy: all) found beans of type 'org.springframework.cloud.config.server.environment.EnvironmentRepository' vaultEnvironmentRepository (OnBeanCondition)

Which makes sense looking at the native configuration:

@Configuration
@ConditionalOnMissingBean(EnvironmentRepository.class)
@Profile("native")
class NativeRepositoryConfiguration {

    @Bean
    public NativeEnvironmentRepository nativeEnvironmentRepository(
            NativeEnvironmentRepositoryFactory factory,
            NativeEnvironmentProperties environmentProperties) {
        return factory.build(environmentProperties);
    }

}

(And other profiles do not have the @ConditionalOnMissingBean(EnvironmentRepository.class))

@ryanjbaxter any feedback about this?

@ask4gilles this should be fixed in Hoxton.BUILD-SNAPSHOT

I also cherry picked the change to the 2.1.x branch as well so it is in Greenwich.BUILD-SNAPSHOT

Was this page helpful?
0 / 5 - 0 ratings