@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) { ConditionMessage.Builder message = ConditionMessage .forCondition("DynamoDB"); Environment environment = context.getEnvironment(); Binder binder = Binder.get(environment); DynamoProperties dynamoProperties = binder.bind("spring.data.dynamodb", DynamoProperties.class) .orElseGet(DynamoProperties::new); String accessKey = dynamoProperties.getAccessKey(); String secretKey = dynamoProperties.getSecretKey(); if (StringUtils.hasLength(accessKey) && StringUtils.hasLength(secretKey)) { return ConditionOutcome.match( message.available("found accessKey and secretKey property")); } return ConditionOutcome.noMatch( message.because("not found accessKey and secretKey property")); } }