Skip to content
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

@PropertySource annotation with multiple values and a name fails to register all property sources [SPR-9127] #13766

Closed
spring-projects-issues opened this issue Feb 16, 2012 · 2 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 16, 2012

Patrick Marschik opened SPR-9127 and commented

When you create an annotation based configuration class with a @PropertySource annotation that provides multiple .properties files and a name for that property source only one property source gets registered since all ResourcePropertySource s have the same name and thus get overwritten by the subsequent property sources.

Example:

@Configuration
@PropertySource(name = "someName", value = {"classpath:a.properties", "classpath:b.properties"})
public class MyConfiguration {
}

this will only register b.properties in the Environment since 2 ResourcePropertySources with the name someName are created and added to the environment.


Affects: 3.1 GA

Issue Links:

Referenced from: commits 4df2a14, e30d610, 41ade68

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Sounds like a trivial enough fix for 3.1.1 still, Chris?

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

commit 41ade68b50b39485b3cf02b9c6fb8eb74962146b
Author: Chris Beams <cbeams@vmware.com>
Date:   Thu Feb 16 16:43:28 2012 +0100

    Fix @PropertySource bug with multiple values
    
    Prior to this commit, specifying a named @PropertySource with multiple
    values would not work as expected. e.g.:
    
      @PropertySource(
          name = "ps",
          value = { "classpath:a.properties", "classpath:b.properties" })
    
    In this scenario, the implementation would register a.properties with
    the name "ps", and subsequently register b.properties with the name
    "ps", overwriting the entry for a.properties.
    
    To fix this behavior, a CompositePropertySource type has been introduced
    which accepts a single name and a set of PropertySource objects to
    iterate over. ConfigurationClassParser's @PropertySource parsing routine
    has been updated to use this composite approach when necessary, i.e.
    when both an explicit name and more than one location have been
    specified.
    
    Note that if no explicit name is specified, the generated property
    source names are enough to distinguish the instances and avoid
    overwriting each other; this is why the composite wrapper is not used
    in these cases.
    
    Issue: SPR-9127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant