Last active
August 29, 2015 14:05
-
-
Save btegenbosch/4e75449e4dc79e03a4e0 to your computer and use it in GitHub Desktop.
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
@Documented | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target(ElementType.TYPE) | |
@Import(FeatureConfiguration.class) | |
public @interface EnableFeature {} | |
@Configuration | |
public class FeatureConfiguration { | |
@Bean | |
@Conditional(NoTemplateFactoryExistsCondition.class) | |
TemplateFactory templateFactory() { | |
return new TemplateFactory(); | |
} | |
} | |
public class NoTemplateFactoryExistsCondition implements Condition { | |
@Override | |
public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) { | |
try { | |
context.getBeanFactory().getBean(TemplateFactory.class); | |
return false; | |
} catch (NoSuchBeanDefinitionException e) { | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment