While trying to use a third party Spring Cloud for AWS to load configuration from Secrets Manager and also a local Properties resource I'm observing this:
With application.properties having:
spring.config.import=configtree:config/,classpath:config.properties
I get this order:
OriginTrackedMapPropertySource {name='Config resource 'class path resource [config.properties]' via location 'classpath:config.properties''}
ConfigTreePropertySource {name='Config tree 'xxx\config''}
OriginTrackedMapPropertySource {name='Config resource 'class path resource [application.properties]' via location 'optional:classpath:/''}
Trying:
spring.config.import=classpath:config.properties,configtree:config/
Gives this order:
ConfigTreePropertySource {name='Config tree 'xxx\config''}
OriginTrackedMapPropertySource {name='Config resource 'class path resource [config.properties]' via location 'classpath:config.properties''}
OriginTrackedMapPropertySource {name='Config resource 'class path resource [application.properties]' via location 'optional:classpath:/''}
So far so good and consistent with documentation which says "Several locations can be specified under a single spring.config.import key. Locations will be processed in the order that they are defined, with later imports taking precedence."
However setting:
spring.config.import=aws-secretsmanager:sample/config,classpath:config.properties
Gives me this:
AwsSecretsManagerPropertySource {name='sample/config'}
OriginTrackedMapPropertySource {name='Config resource 'class path resource [config.properties]' via location 'classpath:config.properties''}
OriginTrackedMapPropertySource {name='Config resource 'class path resource [application.properties]' via location 'optional:classpath:/''}
which makes the Plugin take precedence even if declared before the additional file.
Running with Spring Boot v2.5.6 and spring-cloud-starter-aws-secrets-manager-config v2.4.4.
Comment From: bclozel
Can you reproduce the issue with a supported Spring Boot version? Is this specific to the AWS starter? Have you tried reporting it to the maintainers?
Comment From: tomek82
Retried with Spring 3.1.3 and it's the same. I have not reported to the AWS starter maintainers nor tried other plugins.
Comment From: wilkinsona
I think this is a bug or design choice in Spring Cloud AWS. When it resolves a config data location the result is always considered to be profile-specific. Profile-specific configuration takes precedence over "normal" configuration, so the AwsSecretsManagerPropertySource is ordered before the property source for config.properties.
If it's a bug and not intentional, they may be able to fix the problem by implementing resolve rather than resolveProfileSpecific – this is what Boot's ConfigTreeConfigDataLocationResolver does – but I'm not very familiar with Spring Cloud AWS and may be overlooking something.