Created
July 31, 2017 13:18
-
-
Save milanboers/f95240122a756ea9b23f88d136671ee3 to your computer and use it in GitHub Desktop.
Enable/disable Spring component by property
This file contains 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