001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.autoconfigure.couchbase; 018 019import com.couchbase.client.java.Cluster; 020import com.couchbase.client.java.CouchbaseBucket; 021 022import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 023import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; 024import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 025import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 026import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 027import org.springframework.boot.context.properties.EnableConfigurationProperties; 028import org.springframework.context.annotation.Conditional; 029import org.springframework.context.annotation.Configuration; 030import org.springframework.context.annotation.Import; 031 032/** 033 * {@link EnableAutoConfiguration Auto-configuration} for Couchbase. 034 * 035 * @author EddĂș MelĂ©ndez 036 * @author Stephane Nicoll 037 * @author Yulin Qin 038 * @since 1.4.0 039 */ 040@Configuration 041@ConditionalOnClass({ CouchbaseBucket.class, Cluster.class }) 042@Conditional(CouchbaseAutoConfiguration.CouchbaseCondition.class) 043@EnableConfigurationProperties(CouchbaseProperties.class) 044public class CouchbaseAutoConfiguration { 045 046 @Configuration 047 @ConditionalOnMissingBean(value = CouchbaseConfiguration.class, type = "org.springframework.data.couchbase.config.CouchbaseConfigurer") 048 @Import(CouchbaseConfiguration.class) 049 static class DefaultCouchbaseConfiguration { 050 051 } 052 053 /** 054 * Determine if Couchbase should be configured. This happens if either the 055 * user-configuration defines a {@code CouchbaseConfigurer} or if at least the 056 * "bootstrapHosts" property is specified. 057 * <p> 058 * The reason why we check for the presence of {@code CouchbaseConfigurer} is that it 059 * might use {@link CouchbaseProperties} for its internal customization. 060 */ 061 static class CouchbaseCondition extends AnyNestedCondition { 062 063 CouchbaseCondition() { 064 super(ConfigurationPhase.REGISTER_BEAN); 065 } 066 067 @Conditional(OnBootstrapHostsCondition.class) 068 static class BootstrapHostsProperty { 069 070 } 071 072 @ConditionalOnBean(type = "org.springframework.data.couchbase.config.CouchbaseConfigurer") 073 static class CouchbaseConfigurerAvailable { 074 075 } 076 077 } 078 079}