Purpose: This feature allows Spring Boot applications to conditionally load properties based on the active environment, without requiring complex dynamic configurations. It simplifies configuration management by enabling properties to be loaded only if certain conditions are met, thus reducing the need for manual configuration changes and restarts. This enhancement addresses the current issue where the static configuration approach requires restarting the application to apply any changes, leading to potential downtime and manual interventions.
Implementation Details:
ConditionalOnProperty Annotation: A custom annotation that specifies conditions under which a bean should be created based on property values. OnPropertyCondition Class: Implements the logic to check if a specified property exists in the environment and matches the expected value. MyConfiguration Class: Uses the @ConditionalOnProperty annotation to conditionally create a bean. MyFeatureBean Class: Represents a simple bean with properties and methods to demonstrate functionality. ConditionalOnPropertyTest Class: Verified that the bean is created when the property is set. Verified that the bean is not created when the property is not set.
Comment From: pivotal-cla
@kevchen266 Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-cla
@kevchen266 Thank you for signing the Contributor License Agreement!
Comment From: snicoll
@kevchen266 thanks for the PR. I don't know if you've searched the issue tracker before working on this, but this was requested before and declined (see #18372 and the linked issues). Sorry for the wasted time but the efforts of moving the code here isn't something that would change our mind.