Not planned
Description
In Springboot application,ConfigurationPropertySourcesPropertySource is added to the environment and as first element, the ConfigurationPropertySourcesPropertySource acts as a facade over the existing property sources.
When handling @Value
annotation, org.springframework.core.env.PropertySourcesPropertyResolver#getProperty will be called.
If the property is found then ConfigurationPropertySourcesPropertySource will return the result. otherwise, PropertySourcesPropertyResolver continues to check all subsequent sources. This is a little inefficient for any source that has already been check via ConfigurationPropertySourcesPropertySource.
Activity
philwebb commentedon Nov 16, 2021
I think we may have fixed this already with #17400 (commit 6ad100e) which was added to Spring Boot 2.5. @ShijunDeng Can you check that you're using Spring Boot 2.5 or above? If you're finding an issue with that version could you please please provide a sample that shows the problem.
ShijunDeng commentedon Nov 16, 2021
New similar problem with
ConfigurationPropertySourcesPropertyResolver
in #17400. My Spring Boot version is 2.5.6.ConfigurationPropertySourcesPropertyResolver
is Spring boot source code, but org.springframework.core.env.PropertySourcesPropertyResolver#getProperty is defined in spring-core. The@Value
processor use PropertySourcesPropertyResolver. Set a breakpoint in method org.springframework.core.env.PropertySourcesPropertyResolver#getProperty, it's easy to see thatPropertySourcesPropertyResolver
continues to check all subsequent sources when not found key inConfigurationPropertySourcesPropertySource
.as the screenshort below:

PropertySourcesPropertyResolver
continues to check subsequent source such asSimpleCommandLinePropertySource {name='commandLineArgs'}
ShijunDeng commentedon Dec 7, 2021
@philwebb ,hi,How is it going ?
philwebb commentedon Dec 9, 2021
I need to dig a bit more, but I suspect this resolver is being used which doesn't support the short-circuiting.
[-]Short circuit checking of source already covered by ConfigurationPropertySourcesPropertySource[/-][+]Short circuit @Value injection when using a source already covered by ConfigurationPropertySourcesPropertySource[/+]PropertySourcesPlaceholderConfigurer
to customizePropertyResolver
spring-projects/spring-framework#30304Use configuration resolver to replace standard resolver
Use configuration resolver to replace standard resolver
Use configuration resolver to replace standard resolver
Use configuration resolver to replace standard resolver
Use configuration resolver to replace standard resolver
philwebb commentedon Jun 20, 2023
Closing in favor of PR #34900. Thanks @terminux!