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

Add @ConditionalOnProperties for Conditional Checks on Multiple Properties #43985

Closed
SaeedGooda opened this issue Jan 28, 2025 · 2 comments
Closed
Labels
status: duplicate A duplicate of another issue

Comments

@SaeedGooda
Copy link

SaeedGooda commented Jan 28, 2025

Currently, Spring Boot provides the @ConditionalOnProperty annotation to conditionally load beans or configurations based on a single property. However, there is no built-in support for conditionally loading beans based on multiple properties in a single annotation or use multiple annotations of it. This requires developers to write custom conditions.

Introduce a new annotation, @ConditionalOnProperties, that allows developers to specify multiple @ConditionalOnProperty conditions in a single annotation. This would simplify the configuration and improve readability. Now, developer will have the option to write single condition using @ConditionalOnProperty or use @ConditionalOnProperities like the mentioned:

@ConditionalOnProperties({
        @ConditionalOnProperty(name = "property1", havingValue = "true", matchIfMissing = true),
        @ConditionalOnProperty(name = "property2", havingValue = "false", matchIfMissing = true)
})

In spring boot we can add multiple with the same havingValue and matchIfMissing like this:

@ConditionalOnProperty(name = {"property1", "property2"}, matchIfMissing = true, havingValue = "false")
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 28, 2025
@philwebb
Copy link
Member

Thanks for the suggestion, but there is already an enhancement request open (#2541) that when fixed would effectively create the annotation you're requesting.

@SaeedGooda
Copy link
Author

Thank you

@mhalbritter mhalbritter added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants