You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to have my EnvironmentPostProcessor run conditionally like my autoconfiguration.
For autoconfigurations there are useful annotations @ConditionalOnClass and @ConditionalOnProperty.
Are there equivalent annotations for this which can be used by an EnvironmentPostProcessor?
I cannot find any and so my feature request is to add them.
The text was updated successfully, but these errors were encountered:
There's no annotation support for EnvironmentPostProcessor implementations due to how early they are created which is before the application context exists. Instead of conditions or equivalent annotations, you should use logic in your implementation.
You can use org.springframework.util.ClassUtils.isPresent(String, ClassLoader) as an alternative to @ConditionalOnClass.
A robust equivalent of @ConditionalOnProperty isn't possible in an EnvironmentPostProcessor. Check for a property requires the Environment to have been created and prepared. Part of that preparation is running all of the registered EnvironmentPostProcessor implementations. If a post-processor runs after yours and adds a property or changes a property's value, your post-processor may have done the wrong thing. If you're happy with this ordering limitation, you could use org.springframework.core.env.PropertyResolver.getProperty(String) to check for a property's existence and examine its value.
philwebb
changed the title
ConditionalOn annotation equivalents for EnvironmentPostProcessors
ConditionalOn annotation equivalents for EnvironmentPostProcessors
Apr 1, 2025
Enhancement
I am trying to have my
EnvironmentPostProcessor
run conditionally like my autoconfiguration.For autoconfigurations there are useful annotations
@ConditionalOnClass
and@ConditionalOnProperty
.Are there equivalent annotations for this which can be used by an
EnvironmentPostProcessor
?I cannot find any and so my feature request is to add them.
The text was updated successfully, but these errors were encountered: