-
Notifications
You must be signed in to change notification settings - Fork 40.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Short circuit @Value injection when using a source already covered by ConfigurationPropertySourcesPropertySource #34900
base: main
Are you sure you want to change the base?
Conversation
f85a29d
to
15f27d2
Compare
@@ -20,11 +20,12 @@ | |||
import java.nio.charset.StandardCharsets; | |||
import java.util.function.BiConsumer; | |||
|
|||
import org.springframework.boot.context.properties.source.ConfigurationPropertySources; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logging
package does not allow the content of the context
package to be imported, I am not sure if I need to modify the rules or use other methods to create property resolver.
<disallow pkg="org.springframework.boot.context" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That restriction was introduced in #8611. I'm not sure if we should relax it or not. I wonder if we can get away with using the Environment
directly since it's already a PropertyResolver
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your reply! If you use Environment
directly, we may need to set its ignoreUnresolvableNestedPlaceholders
property to true
to ensure that it is consistent with the original behavior. Since the Environment
is modified, this will also affect the external use of it. Maybe we should make a copy of Environment
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I need to think about this one for a bit.
Hi, I found that
PropertySourcesPropertyResolver
(a resolver that does not support short-circuiting) is used in these places:LoggingSystemProperties
spring-boot/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystemProperties.java
Line 165 in 08ce091
spring-boot/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java
Line 35 in 5817c84
In this case
ConfigurationPropertyName.of(key, true)
will return null, and thendefaultResolver
(inherited fromPropertySourcesPropertyResolver
) will be used for resolution.spring-boot/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertySourcesPropertyResolver.java
Lines 87 to 97 in 5817c84
However the entire process property value will only be retrieved once, the current implementation is fine and we don't need to make any changes.
spring-boot/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertySourcesPropertySource.java
Lines 66 to 68 in 5817c84
PropertySourcesPlaceholderConfigurer
, may need to wait AllowPropertySourcesPlaceholderConfigurer
to customizePropertyResolver
spring-framework#30304 to fixspring-boot/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/PropertyPlaceholderAutoConfiguration.java
Line 43 in 5817c84
Closes gh-28687