@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> attributes = metadata.getAnnotationAttributes(ConditionalOnPropertyPrefix.class.getName()); if (attributes != null && attributes.containsKey("value")) { String prefix = (String) attributes.get("value"); if (prefix != null && !prefix.trim().equals("")) { final String propertyPrefix = !prefix.endsWith(".") ? prefix + "." : prefix; ConfigPropertyProvider configPropertyProvider = EnvironmentConfigPropertyProvider .create(context.getEnvironment()); Set<String> names = configPropertyProvider.getPropertyNames() .filter((n) -> n.startsWith(propertyPrefix)).collect(Collectors.toSet()); if (!names.isEmpty()) { return ConditionOutcome.match(); } return ConditionOutcome.noMatch( ConditionMessage.forCondition(ConditionalOnPropertyPrefix.class).notAvailable(propertyPrefix)); } } return ConditionOutcome.match(); }