@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return !context.getBeanFactory().containsBeanDefinition("bean1"); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { if (context.getBeanFactory().getBeanNamesForAnnotation(Bar.class).length > 0) { return false; } return true; } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return context.getBeanFactory().containsBeanDefinition("bean1"); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return (context.getBeanFactory().getBeanNamesForType(MetadataHolder.class, true, false).length == 0); }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Map<String, Object> attributes = metadata.getAnnotationAttributes(NoBeanOfType.class.getName(), false); Class<?> clazz = (Class<?>) attributes.get("value"); return BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context.getBeanFactory(), clazz).length == 0; } }
ConfigurableListableBeanFactory bf = context.getBeanFactory(); boolean anyMatch = Stream.of(bf.getBeanNamesForType(conditionalClass)) .anyMatch(beanName -> qualifierMatch == isOneMatching(beanName, bf, qualifiers));
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Assert.isInstanceOf(DefaultListableBeanFactory.class, context.getBeanFactory()); DefaultListableBeanFactory listableBeanFactory = (DefaultListableBeanFactory) context .getBeanFactory(); int foundSenders = listableBeanFactory .getBeanNamesForType(Sender.class).length; // Previously we supported 1 Sender bean at a time // which could be overridden by another auto-configuration. // Now we support both the overridden bean and our default zipkinSender bean. // Since this config is adapting the old config we're searching for exactly 1 // `Sender` bean before `ZipkinAutoConfiguration` kicks in. if (foundSenders != 1) { return ConditionOutcome.noMatch( "None or multiple Sender beans found - no reason to apply backwards compatibility"); } int foundReporters = listableBeanFactory .getBeanNamesForType(Reporter.class).length; // Check if we need to provide a Reporter bean for the overridden Sender bean if (foundReporters > 0) { return ConditionOutcome.noMatch( "The old config setup already defines its own Reporter bean"); } return ConditionOutcome.match(); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); List<String> types = CompositeUtils.getCompositeTypeList(context.getEnvironment()); // get EnvironmentRepository types from registered factories List<Class<? extends EnvironmentRepository>> repositoryTypes = new ArrayList<>(); for (String type : types) { String factoryName = CompositeUtils.getFactoryName(type, beanFactory); Type[] actualTypeArguments = CompositeUtils.getEnvironmentRepositoryFactoryTypeParams(beanFactory, factoryName); Class<? extends EnvironmentRepository> repositoryType = (Class<? extends EnvironmentRepository>) actualTypeArguments[0]; repositoryTypes.add(repositoryType); } boolean required = metadata.isAnnotated(ConditionalOnSearchPathLocator.class.getName()); boolean foundSearchPathLocator = repositoryTypes.stream().anyMatch(SearchPathLocator.class::isAssignableFrom); if (required && !foundSearchPathLocator) { return ConditionOutcome.noMatch(ConditionMessage.forCondition(ConditionalOnSearchPathLocator.class).notAvailable(SearchPathLocator.class.getTypeName())); } if (!required && foundSearchPathLocator) { return ConditionOutcome.noMatch(ConditionMessage.forCondition(ConditionalOnMissingSearchPathLocator.class).available(SearchPathLocator.class.getTypeName())); } return ConditionOutcome.match(); } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Map<String, Object> beanAttributes = metadata.getAnnotationAttributes(Bean.class.getName()); String beanName = ((String[]) beanAttributes.get("name"))[0]; if(StringUtils.isEmpty(beanName)) { throw new IllegalStateException("OnMissingBeanCondition can't detect bean name!"); } boolean missingBean = !context.getBeanFactory().containsBean(context.getEnvironment().resolveRequiredPlaceholders(beanName)); return missingBean ? ConditionOutcome.match(beanName + " not found") : ConditionOutcome.noMatch(beanName + " found"); }
ConditionMessage.Builder message = ConditionMessage .forCondition("DevTools DataSource Condition"); String[] dataSourceBeanNames = context.getBeanFactory() .getBeanNamesForType(DataSource.class); if (dataSourceBeanNames.length != 1) { .noMatch(message.didNotFind("a single DataSource bean").atAll()); if (context.getBeanFactory() .getBeanNamesForType(DataSourceProperties.class).length != 1) { return ConditionOutcome.noMatch(
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Map<String, Object> attributes = metadata.getAnnotationAttributes(BeanAvailable.class.getCanonicalName()); if (attributes != null ) { Object value = attributes.get("value"); if (value != null && value instanceof Class) { String[] beans = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context.getBeanFactory(), (Class<?>) value); return beans.length > 0; } } return false; }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Map<String, Object> attributes = metadata.getAnnotationAttributes(BeanAvailable.class.getCanonicalName()); if (attributes != null ) { Object value = attributes.get("value"); if (value != null && value instanceof Class) { String[] beans = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context.getBeanFactory(), (Class<?>) value); return beans.length > 0; } } return false; }
@Override public boolean matches( ConditionContext context, AnnotatedTypeMetadata metadata ) { DhisConfigurationProvider dhisConfigurationProvider = (DhisConfigurationProvider) context.getBeanFactory() .getBean( "dhisConfigurationProvider" ); return dhisConfigurationProvider.getProperty( ConfigurationKey.REDIS_ENABLED ).equalsIgnoreCase( "true" ); }
@Override public boolean matches( ConditionContext context, AnnotatedTypeMetadata metadata ) { DhisConfigurationProvider dhisConfigurationProvider = (DhisConfigurationProvider) context.getBeanFactory() .getBean( "dhisConfigurationProvider" ); return !dhisConfigurationProvider.getProperty( ConfigurationKey.REDIS_ENABLED ).equalsIgnoreCase( "true" ); }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); final String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, ClientFactory.class); for (String beanName : beanNames) { if (hasQualifier(beanFactory, beanName)) { return false; } } return true; }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); final String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, ClientFactory.class); for (String beanName : beanNames) { if (hasQualifier(beanFactory, beanName)) { return false; } } return true; }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); final String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, ClientFactory.class); for (String beanName : beanNames) { if (hasQualifier(beanFactory, beanName)) { return false; } } return true; }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); final String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, ClientFactory.class); for (String beanName : beanNames) { if (hasQualifier(beanFactory, beanName)) { return false; } } return true; }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); final String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, ClientFactory.class); for (String beanName : beanNames) { if (hasQualifier(beanFactory, beanName)) { return false; } } return true; }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String[] enablers = context.getBeanFactory().getBeanNamesForAnnotation(EnableThriftServer.class); for (String name : enablers) { if (context.getBeanFactory().isTypeMatch(name, ThriftServerService.class)) { return ConditionOutcome.match("found @EnableThriftServer on a ThriftServerService"); } } return ConditionOutcome.noMatch("found no @EnableThriftServer on a ThriftServerService"); } }