Describe the bug
Version: spring-cloud-aws: 2.2.6.RELEASE
I needed to create a custom PropertySourceLocator, and this property source needed to be processed after AwsSecretsManagerPropertySourceLocator. I've followed this doc.
I debugged the code and found out that the class PropertySourceBootstrapConfiguration (spring-cloud-context project) is responsible for processing PropertySourceLocator classes. Since this class uses AnnotationAwareOrderComparator.sort(this.propertySourceLocators) to sort available locators, and AwsSecretsManagerPropertySourceLocator has no order defined, it is always processed last.
Alternative 1 - Didn't work for my scenario)
Depending on the component you are trying to setup properties, it is possible to use a different approach, but it won't work for all types of components. It worked for camel-aws2-* components, but it didn't work for setting spring datasource properties, for example.
@Configuration
@Priority(Ordered.HIGHEST_PRECEDENCE)
public class MyCustomPropertySource implements InitializingBean {
@Autowired
private ConfigurableEnvironment env;
@Override
public void afterPropertiesSet() throws Exception {
Properties props = new Properties();
props.put("my-prop-key", "my-prop-value");
env.getPropertySources().addLast(new PropertiesPropertySource("my-custom-props", props));
}
}
Workaround
I ended up doing the following workaround: I've "replaced" class AwsSecretsManagerPropertySourceLocator in my project (copied the class to the project using the same package/class names) and included a @Priority annotation in the class:
@Priority(value = 0)
public class AwsSecretsManagerPropertySourceLocator implements PropertySourceLocator {
After this change, PropertySourceBootstrapConfiguration correctly sorted property locators and my custom property locator could use AwsSecretsManagerPropertySourceLocator properties.
Possible Solution
A possible and simple solution is to add a @Priority, @Order or implement Ordered interface in class AwsSecretsManagerPropertySourceLocator. I don't know if there is another way to create a custom PropertySource that depends on AwsSecretsManagerPropertySourceLocator.
Type: Bug
Component: Secrets Manager
Describe the bug Version: spring-cloud-aws: 2.2.6.RELEASE
I needed to create a custom
PropertySourceLocator
, and this property source needed to be processed afterAwsSecretsManagerPropertySourceLocator
. I've followed this doc.I debugged the code and found out that the class
PropertySourceBootstrapConfiguration
(spring-cloud-context
project) is responsible for processingPropertySourceLocator
classes. Since this class usesAnnotationAwareOrderComparator.sort(this.propertySourceLocators)
to sort available locators, andAwsSecretsManagerPropertySourceLocator
has no order defined, it is always processed last.Alternative 1 - Didn't work for my scenario) Depending on the component you are trying to setup properties, it is possible to use a different approach, but it won't work for all types of components. It worked for
camel-aws2-*
components, but it didn't work for setting spring datasource properties, for example.Workaround I ended up doing the following workaround: I've "replaced" class
AwsSecretsManagerPropertySourceLocator
in my project (copied the class to the project using the same package/class names) and included a@Priority
annotation in the class:After this change,
PropertySourceBootstrapConfiguration
correctly sorted property locators and my custom property locator could useAwsSecretsManagerPropertySourceLocator
properties.Possible Solution A possible and simple solution is to add a
@Priority
,@Order
or implementOrdered
interface in classAwsSecretsManagerPropertySourceLocator
. I don't know if there is another way to create a customPropertySource
that depends onAwsSecretsManagerPropertySourceLocator
.