From 98d2ed85e40884f42b8969b5c4f35e130fc58c04 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 6 Feb 2017 11:11:36 +0100 Subject: [PATCH] Fix broken build Fix couchbase support until a solution is determined for https://jira.spring.io/browse/DATACOUCH-279 See gh-8200 --- .../SpringBootCouchbaseDataConfiguration.java | 50 ++++++++++++++++--- .../CouchbaseDataAutoConfigurationTests.java | 32 +++++++++++- 2 files changed, 72 insertions(+), 10 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseDataConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseDataConfiguration.java index 3d80b8654b..ae348e5855 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseDataConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseDataConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -16,17 +16,22 @@ package org.springframework.boot.autoconfigure.data.couchbase; +import java.util.List; import java.util.Set; +import com.couchbase.client.java.Cluster; +import com.couchbase.client.java.cluster.ClusterInfo; + 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.couchbase.CouchbaseProperties; 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.AbstractCouchbaseDataConfiguration; +import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration; import org.springframework.data.couchbase.config.BeanNames; import org.springframework.data.couchbase.config.CouchbaseConfigurer; import org.springframework.data.couchbase.core.CouchbaseTemplate; @@ -41,24 +46,53 @@ import org.springframework.data.couchbase.repository.support.IndexManager; * @author Stephane Nicoll */ @Configuration -@ConditionalOnMissingBean(AbstractCouchbaseDataConfiguration.class) +@ConditionalOnMissingBean(AbstractCouchbaseConfiguration.class) @ConditionalOnBean(CouchbaseConfigurer.class) -class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfiguration { +class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseConfiguration { private final ApplicationContext applicationContext; - private final CouchbaseDataProperties properties; + private final CouchbaseProperties properties; + + private final CouchbaseDataProperties dataProperties; private final CouchbaseConfigurer couchbaseConfigurer; SpringBootCouchbaseDataConfiguration(ApplicationContext applicationContext, - CouchbaseDataProperties properties, + CouchbaseProperties properties, + CouchbaseDataProperties dataProperties, ObjectProvider couchbaseConfigurer) { this.applicationContext = applicationContext; this.properties = properties; + this.dataProperties = dataProperties; this.couchbaseConfigurer = couchbaseConfigurer.getIfAvailable(); } + @Override + protected List getBootstrapHosts() { + return this.properties.getBootstrapHosts(); + } + + @Override + protected String getBucketName() { + return this.properties.getBucket().getName(); + } + + @Override + protected String getBucketPassword() { + return this.properties.getBucket().getPassword(); + } + + @Override + public Cluster couchbaseCluster() throws Exception { + return couchbaseConfigurer().couchbaseCluster(); + } + + @Override + public ClusterInfo couchbaseClusterInfo() throws Exception { + return couchbaseConfigurer().couchbaseClusterInfo(); + } + @Override protected CouchbaseConfigurer couchbaseConfigurer() { return this.couchbaseConfigurer; @@ -66,7 +100,7 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur @Override protected Consistency getDefaultConsistency() { - return this.properties.getConsistency(); + return this.dataProperties.getConsistency(); } @Override @@ -93,7 +127,7 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur @ConditionalOnMissingBean(name = BeanNames.COUCHBASE_INDEX_MANAGER) @Bean(name = BeanNames.COUCHBASE_INDEX_MANAGER) public IndexManager indexManager() { - if (this.properties.isAutoIndex()) { + if (this.dataProperties.isAutoIndex()) { return new IndexManager(true, true, true); } return new IndexManager(false, false, false); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java index ef632fb8b3..b68abe8586 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java @@ -17,8 +17,11 @@ package org.springframework.boot.autoconfigure.data.couchbase; import java.util.Collections; +import java.util.List; import java.util.Set; +import com.couchbase.client.java.Cluster; +import com.couchbase.client.java.cluster.ClusterInfo; import org.junit.After; import org.junit.Test; @@ -35,7 +38,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.convert.converter.Converter; -import org.springframework.data.couchbase.config.AbstractCouchbaseDataConfiguration; +import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration; import org.springframework.data.couchbase.config.BeanNames; import org.springframework.data.couchbase.config.CouchbaseConfigurer; import org.springframework.data.couchbase.core.CouchbaseTemplate; @@ -147,7 +150,32 @@ public class CouchbaseDataAutoConfigurationTests { } @Configuration - static class CustomCouchbaseConfiguration extends AbstractCouchbaseDataConfiguration { + static class CustomCouchbaseConfiguration extends AbstractCouchbaseConfiguration { + + @Override + protected List getBootstrapHosts() { + return null; + } + + @Override + protected String getBucketName() { + return null; + } + + @Override + protected String getBucketPassword() { + return null; + } + + @Override + public Cluster couchbaseCluster() throws Exception { + return couchbaseConfigurer().couchbaseCluster(); + } + + @Override + public ClusterInfo couchbaseClusterInfo() throws Exception { + return couchbaseConfigurer().couchbaseClusterInfo(); + } @Override protected CouchbaseConfigurer couchbaseConfigurer() {