Skip to content

Short circuit @Value injection when using a source already covered by ConfigurationPropertySourcesPropertySource #28687

Not planned
@ShijunDeng

Description

@ShijunDeng

class ConfigurationPropertySourcesPropertySource extends PropertySource<Iterable<ConfigurationPropertySource>>

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

philwebb commented on Nov 16, 2021

@philwebb
Member

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

ShijunDeng commented on Nov 16, 2021

@ShijunDeng
Author

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:
image

image

PropertySourcesPropertyResolver continues to check subsequent source such as SimpleCommandLinePropertySource {name='commandLineArgs'}

ShijunDeng

ShijunDeng commented on Dec 7, 2021

@ShijunDeng
Author

@philwebb ,hi,How is it going ?

philwebb

philwebb commented on Dec 9, 2021

@philwebb
Member

I need to dig a bit more, but I suspect this resolver is being used which doesn't support the short-circuiting.

changed the title [-]Short circuit checking of source already covered by ConfigurationPropertySourcesPropertySource[/-] [+]Short circuit @Value injection when using a source already covered by ConfigurationPropertySourcesPropertySource[/+] on Dec 9, 2021
added this to the 2.x milestone on Dec 9, 2021
modified the milestones: 2.x, 3.x on Aug 19, 2022

11 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @snicoll@philwebb@spring-projects-issues@ShijunDeng

      Issue actions

        Short circuit @Value injection when using a source already covered by ConfigurationPropertySourcesPropertySource · Issue #28687 · spring-projects/spring-boot