@Override public Outcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); String[] beans = beanFactory.getBeanNamesForType(DispatcherServlet.class, false, false); if (beans.length == 0) { return Outcome.match("no DispatcherServlet found"); } if (Arrays.asList(beans).contains(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) { return Outcome.noMatch( "found DispatcherServlet named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); } return Outcome.match( "multiple DispatcherServlets found and none is named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); }
@Override public ConditionOutcome getMatchOutcome( ConditionContext context, AnnotatedTypeMetadata metadata) { if (anyMatches(context, metadata, this.nonEmbedded, this.embeddedCondition)) { return ConditionOutcome.match("existing auto database detected"); } if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors( context.getBeanFactory(), DataSource.class, true, false) .length > 0) { return ConditionOutcome.match("Existing bean configured database detected"); } return ConditionOutcome.noMatch("no existing bean configured database"); }
private boolean hasBean(ConditionContext context, Class<?> type) { return BeanFactoryUtils.beanNamesForTypeIncludingAncestors( context.getBeanFactory(), type, true, false) .length > 0; }