-
-
Save Kurukshetran/3ad40547daa48d90d455eafaf7310bb6 to your computer and use it in GitHub Desktop.
Enable/disable Spring component by property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@Conditional(MyComponent.EnabledCondition.class) | |
public class MyComponent { | |
protected static class EnabledCondition implements Condition { | |
private static final String ENABLED_PROPERTY = "mycomponent.enabled"; | |
@Override | |
public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) { | |
final Environment environment = context.getEnvironment(); | |
return environment != null && Boolean.valueOf(environment.getProperty(ENABLED_PROPERTY)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment