https://github.com/spring-projects/spring-boot/blob/aaad7727f0fff71b7614bbf10cf4712cd149c84b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertySourcesPropertySource.java#L33
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.
Comment From: philwebb
I think we may have fixed this already with #17400 (commit 6ad100eae618cf6fde2e43fb5b39ad1fdb668988) 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.
Comment From: ShijunDeng
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 that PropertySourcesPropertyResolver continues to check all subsequent sources when not found key in ConfigurationPropertySourcesPropertySource.
as the screenshort below:
PropertySourcesPropertyResolver continues to check subsequent source such as SimpleCommandLinePropertySource {name='commandLineArgs'}
Comment From: ShijunDeng
@philwebb ,hi,How is it going ?
Comment From: philwebb
I need to dig a bit more, but I suspect this resolver is being used which doesn't support the short-circuiting.
Comment From: philwebb
Closing in favor of PR #34900. Thanks @terminux!