Using Spring Cloud Config server without Spring profiles

55 Views Asked by At

I am making a Java library with Spring cloud config server support, which provides different ways to get application properties from different sources depending on feature flags (input environment properties). For example AWS S3 bucket, which will be searched for properties file by an application on startup if feature flag is enabled.

As for now when I add my library in my application it works fine if I add spring profile "awss3" and I see there is some logic on this profile in EnvironmentRepositoryConfiguration class, but when I remove this profile, it starts trying to instantiate DefaultRepositoryConfiguration and expectedly fails.

I've tried to define my own configuration class with awss3 repository bean creation

@Configuration
@ConditionalOnProperty(name = "aws.s3.enabled", havingValue = "true")
public class S3Configuration {

    @Bean
    public AwsS3EnvironmentRepository awsS3EnvironmentRepository(AwsS3EnvironmentRepositoryFactory factory,
                                                                 AwsS3EnvironmentProperties environmentProperties) {
        return factory.build(environmentProperties);
    }
}

and I was expecting that my configuration class will be scanned earlier so Spring knows bean of type EnvironmentRepository is present and never tries to create default one, but actually Spring just checks ConditionalOnMissingBean on DefaultRepositoryConfiguration earlier and context instantiation fails.

I tried to manipulate with ordering using annotations like Order and AutoConfigureBefore, and I tried to remove my configuration file from Autoconfiguration.imports file in properties so it's not interpreted like autoconfiguration, but it does not help.

My aim is just to escape setting up a profile and depend only on feature flags when using AWS S3 as config server, maybe someone has a clue how could I achieve this?

0

There are 0 best solutions below