diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseProperties.java new file mode 100644 index 0000000000..8bdc5d1558 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseProperties.java @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2014 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 + * + * http://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; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Arrays; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +import com.couchbase.client.CouchbaseClient; + +/** + * Couchbase properties. + * + * @author Michael Nitschinger + * @since 1.1.0 + */ +@ConfigurationProperties(prefix = "spring.data.couchbase") +public class CouchbaseProperties { + + private String host = "127.0.0.1"; + + private String bucket = "default"; + + private String password = ""; + + public String getHost() { + return this.host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getBucket() { + return this.bucket; + } + + public void setBucket(String bucket) { + this.bucket = bucket; + } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public CouchbaseClient createClient() throws URISyntaxException, IOException { + return new CouchbaseClient(Arrays.asList(new URI("http://" + getHost() + + ":8091/pools")), getBucket(), getPassword()); + } + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfiguration.java index 2852561617..e28151a56a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 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. @@ -17,9 +17,7 @@ package org.springframework.boot.autoconfigure.data; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; import javax.annotation.PreDestroy; @@ -27,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -41,74 +38,36 @@ import com.couchbase.client.CouchbaseClient; /** * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Couchbase * Repositories. - * + * * @author Michael Nitschinger + * @since 1.1.0 + * @see CouchbaseProperties * @see EnableCouchbaseRepositories */ @Configuration @ConditionalOnClass({ CouchbaseClient.class, CouchbaseRepository.class }) +@Import(CouchbaseRepositoriesAutoConfigureRegistrar.class) +@EnableConfigurationProperties(CouchbaseProperties.class) public class CouchbaseRepositoriesAutoConfiguration { - @Import(CouchbaseRepositoriesAutoConfigureRegistrar.class) - @Configuration - @EnableConfigurationProperties(CouchbaseProperties.class) - protected static class CouchbaseRepositoriesConfiguration { - - @Autowired - private CouchbaseProperties config; - - @PreDestroy - public void close() throws URISyntaxException, IOException { - couchbaseClient().shutdown(); - } - - @Bean - @ConditionalOnMissingBean(CouchbaseClient.class) - CouchbaseClient couchbaseClient() throws URISyntaxException, IOException { - return this.config.couchbaseClient(); - } + @Autowired + private CouchbaseProperties properties; - @Bean - @ConditionalOnMissingBean(CouchbaseTemplate.class) - CouchbaseTemplate couchbaseTemplate(CouchbaseClient couchbaseClient) { - return new CouchbaseTemplate(couchbaseClient); - } + @PreDestroy + public void close() throws URISyntaxException, IOException { + couchbaseClient().shutdown(); } - @ConfigurationProperties(prefix = "spring.data.couchbase") - public static class CouchbaseProperties { - - private String host = "127.0.0.1"; - private String bucket = "default"; - private String password = ""; - - public CouchbaseClient couchbaseClient() throws URISyntaxException, IOException { - return new CouchbaseClient(Arrays.asList(new URI("http://" + getHost() - + ":8091/pools")), getBucket(), getPassword()); - } - - public String getHost() { - return this.host; - } - - public void setHost(String host) { - this.host = host; - } - - public String getBucket() { - return this.bucket; - } - - public void setBucket(String bucket) { - this.bucket = bucket; - } - - public String getPassword() { - return this.password; - } + @Bean + @ConditionalOnMissingBean(CouchbaseClient.class) + CouchbaseClient couchbaseClient() throws URISyntaxException, IOException { + return this.properties.createClient(); + } - public void setPassword(String password) { - this.password = password; - } + @Bean + @ConditionalOnMissingBean(CouchbaseTemplate.class) + CouchbaseTemplate couchbaseTemplate(CouchbaseClient couchbaseClient) { + return new CouchbaseTemplate(couchbaseClient); } + } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfigureRegistrar.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfigureRegistrar.java index 336d2f5f7d..f800cd79d2 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfigureRegistrar.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfigureRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 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,22 +16,22 @@ package org.springframework.boot.autoconfigure.data; -import org.springframework.data.couchbase.repository.config.CouchbaseRepositoryConfigurationExtension; -import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories; -import org.springframework.data.repository.config.RepositoryConfigurationExtension; - import java.lang.annotation.Annotation; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; +import org.springframework.data.couchbase.repository.config.CouchbaseRepositoryConfigurationExtension; +import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories; +import org.springframework.data.repository.config.RepositoryConfigurationExtension; /** * {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Couchbase * Repositories. - * + * * @author Michael Nitschinger + * @since 1.1.0 */ class CouchbaseRepositoriesAutoConfigureRegistrar extends - AbstractRepositoryConfigurationSourceSupport { + AbstractRepositoryConfigurationSourceSupport { @Override protected Class getAnnotation() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfigurationTests.java index efea2bc3b3..cdd9bbd8da 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/CouchbaseRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 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. @@ -32,7 +32,7 @@ import static org.mockito.Mockito.mock; /** * Tests for {@link CouchbaseRepositoriesAutoConfiguration}. - * + * * @author Michael Nitschinger */ public class CouchbaseRepositoriesAutoConfigurationTests { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/City.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/City.java index f1d9e18707..9d203b68ff 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/City.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/City.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 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,14 +16,11 @@ package org.springframework.boot.autoconfigure.data.couchbase; +import java.io.Serializable; + import org.springframework.data.annotation.Id; import org.springframework.data.couchbase.core.mapping.Document; -import java.io.Serializable; - -/** - * @author Michael Nitschinger - */ @Document public class City implements Serializable { @@ -31,8 +28,11 @@ public class City implements Serializable { private String id; private String name; + private String state; + private String country; + private String map; public City(String id, String name, String country) { @@ -42,7 +42,7 @@ public class City implements Serializable { } public String getId() { - return id; + return this.id; } public void setId(String id) { @@ -50,7 +50,7 @@ public class City implements Serializable { } public String getName() { - return name; + return this.name; } public void setName(String name) { @@ -58,7 +58,7 @@ public class City implements Serializable { } public String getState() { - return state; + return this.state; } public void setState(String state) { @@ -66,7 +66,7 @@ public class City implements Serializable { } public String getCountry() { - return country; + return this.country; } public void setCountry(String country) { @@ -74,10 +74,11 @@ public class City implements Serializable { } public String getMap() { - return map; + return this.map; } public void setMap(String map) { this.map = map; } + } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CityRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CityRepository.java index f06acc3cca..455c4986df 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CityRepository.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CityRepository.java @@ -18,8 +18,5 @@ package org.springframework.boot.autoconfigure.data.couchbase; import org.springframework.data.couchbase.repository.CouchbaseRepository; -/** - * @author Michael Nitschinger - */ public interface CityRepository extends CouchbaseRepository { }