diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfiguration.java index 2fa95b99849..588ff956d32 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -36,13 +36,14 @@ import org.springframework.data.solr.repository.support.SolrRepositoryFactoryBea * If active auto configuration does the same as * {@link org.springframework.data.solr.repository.config.EnableSolrRepositories} would * do. - * + * * @author Christoph Strobl + * @since 1.1.0 */ @Configuration @ConditionalOnClass({ SolrServer.class, SolrRepository.class }) @ConditionalOnMissingBean(SolrRepositoryFactoryBean.class) -@Import(SolrRepositoriesAutoConfigureRegstrar.class) +@Import(SolrRepositoriesAutoConfigureRegistrar.class) public class SolrRepositoriesAutoConfiguration { } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigureRegstrar.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigureRegistrar.java similarity index 73% rename from spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigureRegstrar.java rename to spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigureRegistrar.java index b63badcdf88..231761167fc 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigureRegstrar.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigureRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -26,40 +26,23 @@ import org.springframework.data.solr.repository.config.SolrRepositoryConfigExten /** * {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Solr * repositories. - * + * * @author Christoph Strobl + * @since 1.1.0 */ -public class SolrRepositoriesAutoConfigureRegstrar extends +public class SolrRepositoriesAutoConfigureRegistrar extends AbstractRepositoryConfigurationSourceSupport { - /* - * (non-Javadoc) - * - * @see org.springframework.boot.autoconfigure.data. - * AbstractRepositoryConfigurationSourceSupport#getAnnotation() - */ @Override protected Class getAnnotation() { return EnableSolrRepositories.class; } - /* - * (non-Javadoc) - * - * @see org.springframework.boot.autoconfigure.data. - * AbstractRepositoryConfigurationSourceSupport#getConfiguration() - */ @Override protected Class getConfiguration() { return EnableSolrRepositoriesConfiguration.class; } - /* - * (non-Javadoc) - * - * @see org.springframework.boot.autoconfigure.data. - * AbstractRepositoryConfigurationSourceSupport#getRepositoryConfigurationExtension() - */ @Override protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() { return new SolrRepositoryConfigExtension(); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java index 2e8b66035aa..d9510e2f1f7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -22,6 +22,7 @@ import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.impl.CloudSolrServer; import org.apache.solr.client.solrj.impl.HttpSolrServer; 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.EnableConfigurationProperties; @@ -30,16 +31,18 @@ import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; /** - * Enables auto configuration for Solr. - * + * {@link EnableAutoConfiguration Auto-configuration} for Solr + * * @author Christoph Strobl + * @since 1.1.0 */ @Configuration @ConditionalOnClass(SolrServer.class) @EnableConfigurationProperties(SolrProperties.class) public class SolrAutoConfiguration { - private @Autowired SolrProperties properties; + @Autowired + private SolrProperties properties; private SolrServer solrServer; @@ -53,13 +56,11 @@ public class SolrAutoConfiguration { @Bean @ConditionalOnMissingBean public SolrServer solrServer() { - this.solrServer = createSolrServer(); return this.solrServer; } private SolrServer createSolrServer() { - if (StringUtils.hasText(this.properties.getZkHost())) { return new CloudSolrServer(this.properties.getZkHost()); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrProperties.java index 83de83c5b46..9055fe1ce1b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -20,8 +20,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties; /** * Configuration properties for Solr. - * + * * @author Christoph Strobl + * @since 1.1.0 */ @ConfigurationProperties(prefix = "spring.data.solr") public class SolrProperties { @@ -31,7 +32,7 @@ public class SolrProperties { private String zkHost; public String getHost() { - return host; + return this.host; } public void setHost(String host) { @@ -39,7 +40,7 @@ public class SolrProperties { } public String getZkHost() { - return zkHost; + return this.zkHost; } public void setZkHost(String zkHost) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java index 9a84d3f0bd9..2df012490bf 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java @@ -38,7 +38,7 @@ import static org.junit.Assert.assertNotNull; /** * Tests for {@link JpaRepositoriesAutoConfiguration}. - * + * * @author Dave Syer * @author Oliver Gierke */ @@ -83,9 +83,9 @@ public class JpaRepositoriesAutoConfigurationTests { @Configuration @EnableJpaRepositories(basePackageClasses = org.springframework.boot.autoconfigure.data.alt.CityJpaRepository.class, excludeFilters = { - @Filter(type = FilterType.ASSIGNABLE_TYPE, value = CityMongoDbRepository.class), - @Filter(type = FilterType.ASSIGNABLE_TYPE, value = CitySolrRepository.class) }) - @TestAutoConfigurationPackage(City.class) + @Filter(type = FilterType.ASSIGNABLE_TYPE, value = CityMongoDbRepository.class), + @Filter(type = FilterType.ASSIGNABLE_TYPE, value = CitySolrRepository.class) }) + @TestAutoConfigurationPackage(City.class) protected static class CustomConfiguration { } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigurationTests.java index 476c520ee38..3f3b6d3300d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -15,10 +15,6 @@ */ package org.springframework.boot.autoconfigure.data; -import static org.hamcrest.core.IsInstanceOf.*; -import static org.hamcrest.core.IsNull.*; -import static org.junit.Assert.*; - import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.impl.HttpSolrServer; import org.junit.Test; @@ -32,7 +28,13 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Configuration; import org.springframework.data.solr.repository.config.EnableSolrRepositories; +import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.junit.Assert.assertThat; + /** + * Tests for {@link SolrRepositoriesAutoConfiguration} + * * @author Christoph Strobl */ public class SolrRepositoriesAutoConfigurationTests { @@ -41,23 +43,22 @@ public class SolrRepositoriesAutoConfigurationTests { @Test public void testDefaultRepositoryConfiguration() { - initContext(TestConfiguration.class); assertThat(this.context.getBean(CityRepository.class), notNullValue()); - assertThat(this.context.getBean(SolrServer.class), instanceOf(HttpSolrServer.class)); + assertThat(this.context.getBean(SolrServer.class), + instanceOf(HttpSolrServer.class)); } @Test public void testNoRepositoryConfiguration() { - initContext(EmptyConfiguration.class); - assertThat(this.context.getBean(SolrServer.class), instanceOf(HttpSolrServer.class)); + assertThat(this.context.getBean(SolrServer.class), + instanceOf(HttpSolrServer.class)); } @Test public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { - initContext(CustomizedConfiguration.class); assertThat(this.context.getBean(CitySolrRepository.class), notNullValue()); } @@ -65,7 +66,8 @@ public class SolrRepositoriesAutoConfigurationTests { private void initContext(Class configClass) { this.context = new AnnotationConfigApplicationContext(); - this.context.register(configClass, SolrAutoConfiguration.class, SolrRepositoriesAutoConfiguration.class, + this.context.register(configClass, SolrAutoConfiguration.class, + SolrRepositoriesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/City.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/City.java index 9d4584b1630..eaa1c0f3556 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/City.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/City.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.boot.autoconfigure.data.solr; import org.springframework.data.annotation.Id; @@ -29,7 +30,7 @@ public class City { private @Indexed String name; public String getId() { - return id; + return this.id; } public void setId(String id) { @@ -37,7 +38,7 @@ public class City { } public String getName() { - return name; + return this.name; } public void setName(String name) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/CityRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/CityRepository.java index 05cf4bd96ff..f36708a5fd7 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/CityRepository.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/CityRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.boot.autoconfigure.data.solr; import org.springframework.data.domain.Page; diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 9381ea3a65f..074a5644f11 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -192,6 +192,11 @@ spring-boot-starter-data-rest 1.1.0.BUILD-SNAPSHOT + + org.springframework.boot + spring-boot-starter-data-solr + 1.1.0.BUILD-SNAPSHOT + org.springframework.boot spring-boot-starter-freemarker diff --git a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java index a91a3f8c96f..53071d17ed0 100644 --- a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java +++ b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -23,9 +23,6 @@ import org.springframework.data.annotation.Id; import org.springframework.data.solr.core.geo.Point; import org.springframework.data.solr.core.mapping.SolrDocument; -/** - * @author Christoph Strobl - */ @SolrDocument(solrCoreName = "collection1") public class Product { @@ -55,7 +52,7 @@ public class Product { } public String getId() { - return id; + return this.id; } public void setId(String id) { @@ -63,7 +60,7 @@ public class Product { } public String getName() { - return name; + return this.name; } public void setName(String name) { @@ -71,7 +68,7 @@ public class Product { } public Double getPrice() { - return price; + return this.price; } public void setPrice(Double price) { @@ -79,7 +76,7 @@ public class Product { } public List getCategory() { - return category; + return this.category; } public void setCategory(List category) { @@ -87,7 +84,7 @@ public class Product { } public Point getLocation() { - return location; + return this.location; } public void setLocation(Point location) { @@ -96,8 +93,8 @@ public class Product { @Override public String toString() { - return "Product [id=" + id + ", name=" + name + ", price=" + price - + ", category=" + category + ", location=" + location + "]"; + return "Product [id=" + this.id + ", name=" + this.name + ", price=" + this.price + + ", category=" + this.category + ", location=" + this.location + "]"; } } diff --git a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/ProductRepository.java b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/ProductRepository.java index e5c5b926b80..796779bfc30 100644 --- a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/ProductRepository.java +++ b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/ProductRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -20,9 +20,6 @@ import java.util.List; import org.springframework.data.solr.repository.SolrCrudRepository; -/** - * @author Christoph Strobl - */ public interface ProductRepository extends SolrCrudRepository { List findByNameStartingWith(String name); diff --git a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/SampleSolrApplication.java b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/SampleSolrApplication.java index 825c787d189..1cd4eea8c42 100644 --- a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/SampleSolrApplication.java +++ b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/SampleSolrApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -23,9 +23,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -/** - * @author Christoph Strobl - */ @Configuration @EnableAutoConfiguration @ComponentScan @@ -37,17 +34,17 @@ public class SampleSolrApplication implements CommandLineRunner { @Override public void run(String... args) throws Exception { - repository.deleteAll(); + this.repository.deleteAll(); // insert some products - repository.save(new Product("1", "Nintendo Entertainment System")); - repository.save(new Product("2", "Sega Megadrive")); - repository.save(new Product("3", "Sony Playstation")); + this.repository.save(new Product("1", "Nintendo Entertainment System")); + this.repository.save(new Product("2", "Sega Megadrive")); + this.repository.save(new Product("3", "Sony Playstation")); // fetch all System.out.println("Products found by findAll():"); System.out.println("----------------------------"); - for (Product product : repository.findAll()) { + for (Product product : this.repository.findAll()) { System.out.println(product); } System.out.println(); @@ -55,7 +52,7 @@ public class SampleSolrApplication implements CommandLineRunner { // fetch a single product System.out.println("Products founds with findByNameStartingWith('So'):"); System.out.println("--------------------------------"); - for (Product product : repository.findByNameStartingWith("So")) { + for (Product product : this.repository.findByNameStartingWith("So")) { System.out.println(product); } System.out.println(); diff --git a/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java index 2361d5b64d7..2bc86666ef6 100644 --- a/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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,17 +16,13 @@ package sample.data.solr; -import static org.junit.Assert.*; - -import org.apache.solr.client.solrj.SolrServerException; import org.junit.Rule; import org.junit.Test; import org.springframework.boot.test.OutputCapture; import org.springframework.core.NestedCheckedException; -/** - * @author Christoph Strobl - */ +import static org.junit.Assert.assertTrue; + public class SampleSolrApplicationTests { @Rule @@ -37,7 +33,8 @@ public class SampleSolrApplicationTests { try { SampleSolrApplication.main(new String[0]); - } catch (IllegalStateException ex) { + } + catch (IllegalStateException ex) { if (serverNotRunning(ex)) { return; } @@ -51,11 +48,9 @@ public class SampleSolrApplicationTests { @SuppressWarnings("serial") NestedCheckedException nested = new NestedCheckedException("failed", ex) { }; - if (nested.contains(SolrServerException.class)) { - Throwable root = nested.getRootCause(); - if (root.getMessage().contains("Connection refused")) { - return true; - } + Throwable root = nested.getRootCause(); + if (root.getMessage().contains("Connection refused")) { + return true; } return false; }