Spring 启动 2.x.x - 在@ConditionalOnProperty 中组合 2 个条件

Spring Boot 2.x.x - Combine 2 conditions in @ConditionalOnProperty

我有以下界面:

@Primary
@ConditionalOnProperty(value = "ms.couchbase.enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnProperty(value = "iiams.switch.iiamsSingleProcessIdPer100", havingValue = "true", matchIfMissing = true)
public interface AsyncCommonRepository extends CouchbaseRepository<CouchbaseDocument, Long> { }

当然这不会编译。
我想要的只是以某种方式将两者结合起来 @ConditionalOnProperty。我应该使用 @ConditionalOnExpression 吗?
提前致谢!

您可以使用AllNestedConditions组合两个或多个条件:

class AsyncCommonRepositoryCondition extends AllNestedConditions {

    AsyncCommonRepositoryCondition() {
        super(ConfigurationPhase.PARSE_CONFIGURATION);
    }

    @ConditionalOnProperty(value = "ms.couchbase.enabled", havingValue = "true", matchIfMissing = true)
    static class CouchbaseEnabled {

    }

    @ConditionalOnProperty(value = "iiams.switch.iiamsSingleProcessIdPer100", havingValue = "true", matchIfMissing = true)
    static class SingleProcessIdPer100 {

    }

}

然后可以在您的存储库上使用此条件:

@Primary
@Conditional(AsyncCommonRepositoryCondition.class)
public interface AsyncCommonRepository extends CouchbaseRepository<CouchbaseDocument, Long> { }