From 4968900b1d4feee9c93ebccb90227436a35d59cc Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 8 Oct 2015 16:19:56 +0100 Subject: [PATCH] Gracefully disable Solr auto-configuration when Solr 5 is on classpath Previously, if Solr 5 was on the classpath, SolrAutoConfiguration would fail with a rather cryptic error message due to a change in the inheritance hierarchy of CloudSolrServer between Solr 4 and Solr 5. This commit updates SolrAutoConfiguration to be conditional on a class that exists in Solr 4 but was removed in Solr 5. This has the effect of switching off the auto-configuration when Solr 5 is on the classpath, allowing the auto-configuration report to be used to identify why the configuration was disabled. The documentation has also been updated to state that Spring Boot does not currently support Solr 5.0. Closes gh-2795 --- .../boot/autoconfigure/solr/SolrAutoConfiguration.java | 6 ++++-- .../src/main/asciidoc/spring-boot-features.adoc | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) 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 f49f7e69071..4494f68bf03 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 @@ -21,6 +21,7 @@ import javax.annotation.PreDestroy; 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.apache.solr.common.cloud.HashPartitioner; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -31,13 +32,14 @@ import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; /** - * {@link EnableAutoConfiguration Auto-configuration} for Solr. + * {@link EnableAutoConfiguration Auto-configuration} for Solr 4.x. * * @author Christoph Strobl * @since 1.1.0 */ @Configuration -@ConditionalOnClass({ HttpSolrServer.class, CloudSolrServer.class }) +@ConditionalOnClass({ HttpSolrServer.class, CloudSolrServer.class, + HashPartitioner.class }) @EnableConfigurationProperties(SolrProperties.class) public class SolrAutoConfiguration { diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 43c6bf5b9cb..93725b2ec8c 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -2705,11 +2705,14 @@ https://github.com/spring-projects/spring-data-gemfire/blob/master/src/main/java [[boot-features-solr]] === Solr http://lucene.apache.org/solr/[Apache Solr] is a search engine. Spring Boot offers basic -auto-configuration for the Solr client library and abstractions on top of it provided by +auto-configuration for the Solr 4 client library and abstractions on top of it provided by https://github.com/spring-projects/spring-data-solr[Spring Data Solr]. There is a `spring-boot-starter-data-solr` '`Starter POM`' for collecting the dependencies in a convenient way. +TIP: Solr 5 is currently not supported and the auto-configuration will not be enabled by +a Solr 5 dependency. + [[boot-features-connecting-to-solr]]