Skip to content

Support @PropertySource as an attribute in @Configuration #34680

@brundabharadwaj

Description

@brundabharadwaj

Enhancement request:

Proposal: Support @PropertySource as an Attribute of @Configuration

Background

Currently, in Spring, we specify external property sources using @PropertySource separately from @Configuration. This means that when defining a configuration class, we must explicitly use @PropertySource to load properties from an external file.

Example:

@Configuration
@PropertySource("classpath:application-custom.properties")
public class AppConfig {
}

However, it would be more intuitive and concise if we could define property sources directly as an attribute of @Configuration, making the configuration more self-contained.


Proposal

Introduce an optional attribute propertySource in @Configuration to specify external property files.

Example of the proposed approach:

@Configuration(propertySource = "classpath:application-custom.properties")
public class AppConfig {
}

Benefits:

  • Reduces redundancy by allowing property source definitions within @Configuration.
  • Improves readability and maintainability.
  • Keeps @PropertySource optional for backward compatibility.

Alternative Considerations

  1. Backward Compatibility: The existing @PropertySource should still be supported for cases where multiple property sources are needed.
  2. Multiple Property Sources: If needed, the propertySource attribute could accept an array to support multiple files.

Would love to hear thoughts on this proposal and whether this would be a valuable addition and I am open to contribute 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions