Skip to content

Instantly share code, notes, and snippets.

@btegenbosch
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btegenbosch/4e75449e4dc79e03a4e0 to your computer and use it in GitHub Desktop.
Save btegenbosch/4e75449e4dc79e03a4e0 to your computer and use it in GitHub Desktop.
@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