Browse Source
This commit configures Spring Data Couchbase explicitly rather than relying on the abstract configuration class. This has the advantage of simplifying the auto-configuration and let it us proxy-free configuration classes. Spring Boot no longer uses or interacts with CouchbaseConfigurer. Users relying on that to teach Spring Boot which components to use should rely on `@Primary` flag instead in case of multiple beans of the same type. `CouchbaseConfiguration` is no longer public as extending from it is no longer necessary. If the `CouchbaseEnvironment` has to be customized, a `CouchbaseEnvironmentBuilderCustomizer` bean can be registered to tune the auto-configured environment. Closes gh-20533pull/20557/head
21 changed files with 413 additions and 694 deletions
@ -1,159 +0,0 @@
@@ -1,159 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.couchbase; |
||||
|
||||
import java.util.List; |
||||
|
||||
import com.couchbase.client.core.env.KeyValueServiceConfig; |
||||
import com.couchbase.client.core.env.QueryServiceConfig; |
||||
import com.couchbase.client.core.env.ViewServiceConfig; |
||||
import com.couchbase.client.java.Bucket; |
||||
import com.couchbase.client.java.Cluster; |
||||
import com.couchbase.client.java.CouchbaseCluster; |
||||
import com.couchbase.client.java.cluster.ClusterInfo; |
||||
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment; |
||||
|
||||
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties.Endpoints; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.context.annotation.DependsOn; |
||||
import org.springframework.context.annotation.Primary; |
||||
|
||||
/** |
||||
* Support class to configure Couchbase based on {@link CouchbaseProperties}. |
||||
* |
||||
* @author Stephane Nicoll |
||||
* @author Brian Clozel |
||||
* @since 2.1.0 |
||||
*/ |
||||
@Configuration |
||||
public class CouchbaseConfiguration { |
||||
|
||||
private final CouchbaseProperties properties; |
||||
|
||||
public CouchbaseConfiguration(CouchbaseProperties properties) { |
||||
this.properties = properties; |
||||
} |
||||
|
||||
@Bean |
||||
@Primary |
||||
public DefaultCouchbaseEnvironment couchbaseEnvironment() { |
||||
return initializeEnvironmentBuilder(this.properties).build(); |
||||
} |
||||
|
||||
@Bean |
||||
@Primary |
||||
public Cluster couchbaseCluster() { |
||||
CouchbaseCluster couchbaseCluster = CouchbaseCluster.create(couchbaseEnvironment(), determineBootstrapHosts()); |
||||
if (isRoleBasedAccessControlEnabled()) { |
||||
return couchbaseCluster.authenticate(this.properties.getUsername(), this.properties.getPassword()); |
||||
} |
||||
return couchbaseCluster; |
||||
} |
||||
|
||||
/** |
||||
* Determine the Couchbase nodes to bootstrap from. |
||||
* @return the Couchbase nodes to bootstrap from |
||||
*/ |
||||
protected List<String> determineBootstrapHosts() { |
||||
return this.properties.getBootstrapHosts(); |
||||
} |
||||
|
||||
@Bean |
||||
@Primary |
||||
@DependsOn("couchbaseClient") |
||||
public ClusterInfo couchbaseClusterInfo() { |
||||
if (isRoleBasedAccessControlEnabled()) { |
||||
return couchbaseCluster().clusterManager().info(); |
||||
} |
||||
return couchbaseCluster() |
||||
.clusterManager(this.properties.getBucket().getName(), this.properties.getBucket().getPassword()) |
||||
.info(); |
||||
} |
||||
|
||||
@Bean |
||||
@Primary |
||||
public Bucket couchbaseClient() { |
||||
if (isRoleBasedAccessControlEnabled()) { |
||||
return couchbaseCluster().openBucket(this.properties.getBucket().getName()); |
||||
} |
||||
return couchbaseCluster().openBucket(this.properties.getBucket().getName(), |
||||
this.properties.getBucket().getPassword()); |
||||
} |
||||
|
||||
private boolean isRoleBasedAccessControlEnabled() { |
||||
return this.properties.getUsername() != null && this.properties.getPassword() != null; |
||||
} |
||||
|
||||
/** |
||||
* Initialize an environment builder based on the specified settings. |
||||
* @param properties the couchbase properties to use |
||||
* @return the {@link DefaultCouchbaseEnvironment} builder. |
||||
*/ |
||||
protected DefaultCouchbaseEnvironment.Builder initializeEnvironmentBuilder(CouchbaseProperties properties) { |
||||
CouchbaseProperties.Endpoints endpoints = properties.getEnv().getEndpoints(); |
||||
CouchbaseProperties.Timeouts timeouts = properties.getEnv().getTimeouts(); |
||||
CouchbaseProperties.Bootstrap bootstrap = properties.getEnv().getBootstrap(); |
||||
DefaultCouchbaseEnvironment.Builder builder = DefaultCouchbaseEnvironment.builder(); |
||||
if (bootstrap.getHttpDirectPort() != null) { |
||||
builder.bootstrapHttpDirectPort(bootstrap.getHttpDirectPort()); |
||||
} |
||||
if (bootstrap.getHttpSslPort() != null) { |
||||
builder.bootstrapHttpSslPort(bootstrap.getHttpSslPort()); |
||||
} |
||||
if (timeouts.getConnect() != null) { |
||||
builder = builder.connectTimeout(timeouts.getConnect().toMillis()); |
||||
} |
||||
builder = builder.keyValueServiceConfig(KeyValueServiceConfig.create(endpoints.getKeyValue())); |
||||
if (timeouts.getKeyValue() != null) { |
||||
builder = builder.kvTimeout(timeouts.getKeyValue().toMillis()); |
||||
} |
||||
if (timeouts.getQuery() != null) { |
||||
builder = builder.queryTimeout(timeouts.getQuery().toMillis()); |
||||
builder = builder.queryServiceConfig(getQueryServiceConfig(endpoints)); |
||||
builder = builder.viewServiceConfig(getViewServiceConfig(endpoints)); |
||||
} |
||||
if (timeouts.getSocketConnect() != null) { |
||||
builder = builder.socketConnectTimeout((int) timeouts.getSocketConnect().toMillis()); |
||||
} |
||||
if (timeouts.getView() != null) { |
||||
builder = builder.viewTimeout(timeouts.getView().toMillis()); |
||||
} |
||||
CouchbaseProperties.Ssl ssl = properties.getEnv().getSsl(); |
||||
if (ssl.getEnabled()) { |
||||
builder = builder.sslEnabled(true); |
||||
if (ssl.getKeyStore() != null) { |
||||
builder = builder.sslKeystoreFile(ssl.getKeyStore()); |
||||
} |
||||
if (ssl.getKeyStorePassword() != null) { |
||||
builder = builder.sslKeystorePassword(ssl.getKeyStorePassword()); |
||||
} |
||||
} |
||||
return builder; |
||||
} |
||||
|
||||
private QueryServiceConfig getQueryServiceConfig(Endpoints endpoints) { |
||||
return QueryServiceConfig.create(endpoints.getQueryservice().getMinEndpoints(), |
||||
endpoints.getQueryservice().getMaxEndpoints()); |
||||
} |
||||
|
||||
private ViewServiceConfig getViewServiceConfig(Endpoints endpoints) { |
||||
return ViewServiceConfig.create(endpoints.getViewservice().getMinEndpoints(), |
||||
endpoints.getViewservice().getMaxEndpoints()); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.couchbase; |
||||
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment; |
||||
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment; |
||||
|
||||
/** |
||||
* Callback interface that can be implemented by beans wishing to customize the |
||||
* {@link CouchbaseEnvironment} via a {@link DefaultCouchbaseEnvironment.Builder} whilst |
||||
* retaining default auto-configuration. |
||||
* |
||||
* @author Stephane Nicoll |
||||
* @since 2.3.0 |
||||
*/ |
||||
@FunctionalInterface |
||||
public interface CouchbaseEnvironmentBuilderCustomizer { |
||||
|
||||
/** |
||||
* Customize the {@link DefaultCouchbaseEnvironment.Builder}. |
||||
* @param builder the builder to customize |
||||
*/ |
||||
void customize(DefaultCouchbaseEnvironment.Builder builder); |
||||
|
||||
} |
||||
@ -1,52 +0,0 @@
@@ -1,52 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.data.couchbase; |
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
||||
import org.springframework.boot.autoconfigure.couchbase.CouchbaseConfiguration; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.couchbase.config.CouchbaseConfigurer; |
||||
|
||||
/** |
||||
* Adapt the core Couchbase configuration to an expected {@link CouchbaseConfigurer} if |
||||
* necessary. |
||||
* |
||||
* @author Stephane Nicoll |
||||
*/ |
||||
@Configuration(proxyBeanMethods = false) |
||||
@ConditionalOnClass(CouchbaseConfigurer.class) |
||||
@ConditionalOnBean(CouchbaseConfiguration.class) |
||||
class CouchbaseConfigurerAdapterConfiguration { |
||||
|
||||
private final CouchbaseConfiguration configuration; |
||||
|
||||
CouchbaseConfigurerAdapterConfiguration(CouchbaseConfiguration configuration) { |
||||
this.configuration = configuration; |
||||
} |
||||
|
||||
@Bean |
||||
@ConditionalOnMissingBean |
||||
CouchbaseConfigurer springBootCouchbaseConfigurer() throws Exception { |
||||
return new SpringBootCouchbaseConfigurer(this.configuration.couchbaseEnvironment(), |
||||
this.configuration.couchbaseCluster(), this.configuration.couchbaseClusterInfo(), |
||||
this.configuration.couchbaseClient()); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,119 @@
@@ -0,0 +1,119 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.data.couchbase; |
||||
|
||||
import java.util.Collections; |
||||
|
||||
import com.couchbase.client.java.Bucket; |
||||
import com.couchbase.client.java.cluster.ClusterInfo; |
||||
|
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; |
||||
import org.springframework.boot.autoconfigure.domain.EntityScanner; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.annotation.Persistent; |
||||
import org.springframework.data.couchbase.config.BeanNames; |
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate; |
||||
import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions; |
||||
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter; |
||||
import org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService; |
||||
import org.springframework.data.couchbase.core.convert.translation.TranslationService; |
||||
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext; |
||||
import org.springframework.data.couchbase.core.mapping.Document; |
||||
import org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping; |
||||
import org.springframework.data.couchbase.repository.support.IndexManager; |
||||
import org.springframework.data.mapping.model.FieldNamingStrategy; |
||||
|
||||
/** |
||||
* Configuration for Spring Data's couchbase support. |
||||
* |
||||
* @author Stephane Nicoll |
||||
*/ |
||||
@Configuration(proxyBeanMethods = false) |
||||
class CouchbaseDataConfiguration { |
||||
|
||||
@Bean(name = BeanNames.COUCHBASE_MAPPING_CONVERTER) |
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_MAPPING_CONVERTER) |
||||
MappingCouchbaseConverter couchbaseMappingConverter(CouchbaseDataProperties properties, |
||||
CouchbaseMappingContext couchbaseMappingContext, CouchbaseCustomConversions couchbaseCustomConversions) { |
||||
MappingCouchbaseConverter converter = new MappingCouchbaseConverter(couchbaseMappingContext, |
||||
properties.getTypeKey()); |
||||
converter.setCustomConversions(couchbaseCustomConversions); |
||||
return converter; |
||||
} |
||||
|
||||
@Bean(name = BeanNames.COUCHBASE_TRANSLATION_SERVICE) |
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_TRANSLATION_SERVICE) |
||||
TranslationService couchbaseTranslationService() { |
||||
return new JacksonTranslationService(); |
||||
} |
||||
|
||||
@Bean(name = BeanNames.COUCHBASE_MAPPING_CONTEXT) |
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_MAPPING_CONTEXT) |
||||
CouchbaseMappingContext couchbaseMappingContext(CouchbaseDataProperties properties, |
||||
ApplicationContext applicationContext, CouchbaseCustomConversions couchbaseCustomConversions) |
||||
throws Exception { |
||||
CouchbaseMappingContext mappingContext = new CouchbaseMappingContext(); |
||||
mappingContext |
||||
.setInitialEntitySet(new EntityScanner(applicationContext).scan(Document.class, Persistent.class)); |
||||
mappingContext.setSimpleTypeHolder(couchbaseCustomConversions.getSimpleTypeHolder()); |
||||
Class<?> fieldNamingStrategy = properties.getFieldNamingStrategy(); |
||||
if (fieldNamingStrategy != null) { |
||||
mappingContext |
||||
.setFieldNamingStrategy((FieldNamingStrategy) BeanUtils.instantiateClass(fieldNamingStrategy)); |
||||
} |
||||
return mappingContext; |
||||
} |
||||
|
||||
@Bean(name = BeanNames.COUCHBASE_CUSTOM_CONVERSIONS) |
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_CUSTOM_CONVERSIONS) |
||||
CouchbaseCustomConversions couchbaseCustomConversions() { |
||||
return new CouchbaseCustomConversions(Collections.emptyList()); |
||||
} |
||||
|
||||
@Bean(name = BeanNames.COUCHBASE_INDEX_MANAGER) |
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_INDEX_MANAGER) |
||||
IndexManager indexManager(CouchbaseDataProperties properties) { |
||||
if (properties.isAutoIndex()) { |
||||
return new IndexManager(true, true, true); |
||||
} |
||||
return new IndexManager(false, false, false); |
||||
} |
||||
|
||||
@Bean(name = BeanNames.COUCHBASE_TEMPLATE) |
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_TEMPLATE) |
||||
@ConditionalOnBean({ ClusterInfo.class, Bucket.class }) |
||||
CouchbaseTemplate couchbaseTemplate(CouchbaseDataProperties properties, ClusterInfo clusterInfo, Bucket bucket, |
||||
MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService translationService) { |
||||
CouchbaseTemplate template = new CouchbaseTemplate(clusterInfo, bucket, mappingCouchbaseConverter, |
||||
translationService); |
||||
template.setDefaultConsistency(properties.getConsistency()); |
||||
return template; |
||||
} |
||||
|
||||
@Bean(name = BeanNames.COUCHBASE_OPERATIONS_MAPPING) |
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_OPERATIONS_MAPPING) |
||||
@ConditionalOnSingleCandidate(CouchbaseTemplate.class) |
||||
RepositoryOperationsMapping repositoryOperationsMapping(CouchbaseTemplate couchbaseTemplate) { |
||||
return new RepositoryOperationsMapping(couchbaseTemplate); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.data.couchbase; |
||||
|
||||
import com.couchbase.client.java.Bucket; |
||||
import com.couchbase.client.java.cluster.ClusterInfo; |
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.couchbase.config.BeanNames; |
||||
import org.springframework.data.couchbase.core.RxJavaCouchbaseTemplate; |
||||
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter; |
||||
import org.springframework.data.couchbase.core.convert.translation.TranslationService; |
||||
import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOperationsMapping; |
||||
|
||||
/** |
||||
* Configuration for Spring Data's couchbase reactive support. |
||||
* |
||||
* @author Stephane Nicoll |
||||
*/ |
||||
@Configuration(proxyBeanMethods = false) |
||||
class CouchbaseReactiveDataConfiguration { |
||||
|
||||
@Bean(name = BeanNames.RXJAVA1_COUCHBASE_TEMPLATE) |
||||
@ConditionalOnMissingBean(name = BeanNames.RXJAVA1_COUCHBASE_TEMPLATE) |
||||
@ConditionalOnBean({ ClusterInfo.class, Bucket.class }) |
||||
RxJavaCouchbaseTemplate reactiveCouchbaseTemplate(CouchbaseDataProperties properties, ClusterInfo clusterInfo, |
||||
Bucket bucket, MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService translationService) { |
||||
RxJavaCouchbaseTemplate template = new RxJavaCouchbaseTemplate(clusterInfo, bucket, mappingCouchbaseConverter, |
||||
translationService); |
||||
template.setDefaultConsistency(properties.getConsistency()); |
||||
return template; |
||||
} |
||||
|
||||
@Bean(name = BeanNames.REACTIVE_COUCHBASE_OPERATIONS_MAPPING) |
||||
@ConditionalOnMissingBean(name = BeanNames.REACTIVE_COUCHBASE_OPERATIONS_MAPPING) |
||||
@ConditionalOnSingleCandidate(RxJavaCouchbaseTemplate.class) |
||||
ReactiveRepositoryOperationsMapping reactiveRepositoryOperationsMapping( |
||||
RxJavaCouchbaseTemplate reactiveCouchbaseTemplate) { |
||||
return new ReactiveRepositoryOperationsMapping(reactiveCouchbaseTemplate); |
||||
} |
||||
|
||||
} |
||||
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.data.couchbase; |
||||
|
||||
import com.couchbase.client.java.Bucket; |
||||
import com.couchbase.client.java.Cluster; |
||||
import com.couchbase.client.java.cluster.ClusterInfo; |
||||
import com.couchbase.client.java.env.CouchbaseEnvironment; |
||||
|
||||
import org.springframework.data.couchbase.config.CouchbaseConfigurer; |
||||
|
||||
/** |
||||
* A simple {@link CouchbaseConfigurer} implementation. |
||||
* |
||||
* @author Stephane Nicoll |
||||
* @since 1.4.0 |
||||
*/ |
||||
public class SpringBootCouchbaseConfigurer implements CouchbaseConfigurer { |
||||
|
||||
private final CouchbaseEnvironment env; |
||||
|
||||
private final Cluster cluster; |
||||
|
||||
private final ClusterInfo clusterInfo; |
||||
|
||||
private final Bucket bucket; |
||||
|
||||
public SpringBootCouchbaseConfigurer(CouchbaseEnvironment env, Cluster cluster, ClusterInfo clusterInfo, |
||||
Bucket bucket) { |
||||
this.env = env; |
||||
this.cluster = cluster; |
||||
this.clusterInfo = clusterInfo; |
||||
this.bucket = bucket; |
||||
} |
||||
|
||||
@Override |
||||
public CouchbaseEnvironment couchbaseEnvironment() throws Exception { |
||||
return this.env; |
||||
} |
||||
|
||||
@Override |
||||
public Cluster couchbaseCluster() throws Exception { |
||||
return this.cluster; |
||||
} |
||||
|
||||
@Override |
||||
public ClusterInfo couchbaseClusterInfo() throws Exception { |
||||
return this.clusterInfo; |
||||
} |
||||
|
||||
@Override |
||||
public Bucket couchbaseClient() throws Exception { |
||||
return this.bucket; |
||||
} |
||||
|
||||
} |
||||
@ -1,105 +0,0 @@
@@ -1,105 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.data.couchbase; |
||||
|
||||
import java.util.Set; |
||||
|
||||
import org.springframework.beans.factory.ObjectProvider; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
||||
import org.springframework.boot.autoconfigure.domain.EntityScanner; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.annotation.Persistent; |
||||
import org.springframework.data.convert.CustomConversions; |
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseDataConfiguration; |
||||
import org.springframework.data.couchbase.config.BeanNames; |
||||
import org.springframework.data.couchbase.config.CouchbaseConfigurer; |
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate; |
||||
import org.springframework.data.couchbase.core.mapping.Document; |
||||
import org.springframework.data.couchbase.core.query.Consistency; |
||||
import org.springframework.data.couchbase.repository.support.IndexManager; |
||||
|
||||
/** |
||||
* Configure Spring Data's couchbase support. |
||||
* |
||||
* @author Stephane Nicoll |
||||
*/ |
||||
@Configuration |
||||
@ConditionalOnMissingBean(AbstractCouchbaseDataConfiguration.class) |
||||
@ConditionalOnBean(CouchbaseConfigurer.class) |
||||
class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfiguration { |
||||
|
||||
private final ApplicationContext applicationContext; |
||||
|
||||
private final CouchbaseDataProperties properties; |
||||
|
||||
private final CouchbaseConfigurer couchbaseConfigurer; |
||||
|
||||
SpringBootCouchbaseDataConfiguration(ApplicationContext applicationContext, CouchbaseDataProperties properties, |
||||
ObjectProvider<CouchbaseConfigurer> couchbaseConfigurer) { |
||||
this.applicationContext = applicationContext; |
||||
this.properties = properties; |
||||
this.couchbaseConfigurer = couchbaseConfigurer.getIfAvailable(); |
||||
} |
||||
|
||||
@Override |
||||
protected CouchbaseConfigurer couchbaseConfigurer() { |
||||
return this.couchbaseConfigurer; |
||||
} |
||||
|
||||
@Override |
||||
protected Consistency getDefaultConsistency() { |
||||
return this.properties.getConsistency(); |
||||
} |
||||
|
||||
@Override |
||||
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException { |
||||
return new EntityScanner(this.applicationContext).scan(Document.class, Persistent.class); |
||||
} |
||||
|
||||
@Override |
||||
public String typeKey() { |
||||
return this.properties.getTypeKey(); |
||||
} |
||||
|
||||
@Override |
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_TEMPLATE) |
||||
@Bean(name = BeanNames.COUCHBASE_TEMPLATE) |
||||
public CouchbaseTemplate couchbaseTemplate() throws Exception { |
||||
return super.couchbaseTemplate(); |
||||
} |
||||
|
||||
@Override |
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_CUSTOM_CONVERSIONS) |
||||
@Bean(name = BeanNames.COUCHBASE_CUSTOM_CONVERSIONS) |
||||
public CustomConversions customConversions() { |
||||
return super.customConversions(); |
||||
} |
||||
|
||||
@Override |
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_INDEX_MANAGER) |
||||
@Bean(name = BeanNames.COUCHBASE_INDEX_MANAGER) |
||||
public IndexManager indexManager() { |
||||
if (this.properties.isAutoIndex()) { |
||||
return new IndexManager(true, true, true); |
||||
} |
||||
return new IndexManager(false, false, false); |
||||
} |
||||
|
||||
} |
||||
@ -1,75 +0,0 @@
@@ -1,75 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.data.couchbase; |
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.couchbase.config.AbstractReactiveCouchbaseDataConfiguration; |
||||
import org.springframework.data.couchbase.config.BeanNames; |
||||
import org.springframework.data.couchbase.config.CouchbaseConfigurer; |
||||
import org.springframework.data.couchbase.core.RxJavaCouchbaseTemplate; |
||||
import org.springframework.data.couchbase.core.query.Consistency; |
||||
import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOperationsMapping; |
||||
|
||||
/** |
||||
* Configure Spring Data's reactive couchbase support. |
||||
* |
||||
* @author Alex Derkach |
||||
*/ |
||||
@Configuration |
||||
@ConditionalOnMissingBean(AbstractReactiveCouchbaseDataConfiguration.class) |
||||
@ConditionalOnBean(CouchbaseConfigurer.class) |
||||
class SpringBootCouchbaseReactiveDataConfiguration extends AbstractReactiveCouchbaseDataConfiguration { |
||||
|
||||
private final CouchbaseDataProperties properties; |
||||
|
||||
private final CouchbaseConfigurer couchbaseConfigurer; |
||||
|
||||
SpringBootCouchbaseReactiveDataConfiguration(CouchbaseDataProperties properties, |
||||
CouchbaseConfigurer couchbaseConfigurer) { |
||||
this.properties = properties; |
||||
this.couchbaseConfigurer = couchbaseConfigurer; |
||||
} |
||||
|
||||
@Override |
||||
protected CouchbaseConfigurer couchbaseConfigurer() { |
||||
return this.couchbaseConfigurer; |
||||
} |
||||
|
||||
@Override |
||||
protected Consistency getDefaultConsistency() { |
||||
return this.properties.getConsistency(); |
||||
} |
||||
|
||||
@Override |
||||
@ConditionalOnMissingBean(name = BeanNames.RXJAVA1_COUCHBASE_TEMPLATE) |
||||
@Bean(name = BeanNames.RXJAVA1_COUCHBASE_TEMPLATE) |
||||
public RxJavaCouchbaseTemplate reactiveCouchbaseTemplate() throws Exception { |
||||
return super.reactiveCouchbaseTemplate(); |
||||
} |
||||
|
||||
@Override |
||||
@ConditionalOnMissingBean(name = BeanNames.REACTIVE_COUCHBASE_OPERATIONS_MAPPING) |
||||
@Bean(name = BeanNames.REACTIVE_COUCHBASE_OPERATIONS_MAPPING) |
||||
public ReactiveRepositoryOperationsMapping reactiveRepositoryOperationsMapping( |
||||
RxJavaCouchbaseTemplate reactiveCouchbaseTemplate) throws Exception { |
||||
return super.reactiveRepositoryOperationsMapping(reactiveCouchbaseTemplate); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue