-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed as not planned
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
Description
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
@PropertySourceoptional for backward compatibility.
Alternative Considerations
- Backward Compatibility: The existing
@PropertySourceshould still be supported for cases where multiple property sources are needed. - Multiple Property Sources: If needed, the
propertySourceattribute 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
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply