Upgrade to Spring Data Hopper M1

Closes gh-5120
This commit is contained in:
Stephane Nicoll
2016-02-15 14:22:40 +01:00
parent 1c365662b0
commit b205e02e33
9 changed files with 63 additions and 65 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2016 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,7 +16,7 @@
package org.springframework.boot.autoconfigure.data.solr;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -30,11 +30,9 @@ import org.springframework.data.solr.repository.support.SolrRepositoryFactoryBea
/**
* Enables auto configuration for Spring Data Solr repositories.
* <p>
* Activates when there is no bean of type
* {@link org.springframework.data.solr.repository.support.SolrRepositoryFactoryBean}
* found in context, and both
* {@link org.springframework.data.solr.repository.SolrRepository} and
* {@link org.apache.solr.client.solrj.SolrServer} can be found on classpath.
* Activates when there is no bean of type {@link SolrRepositoryFactoryBean} found in
* context, and both {@link SolrRepository} and {@link SolrClient} can be found on
* classpath.
* </p>
* If active auto configuration does the same as
* {@link org.springframework.data.solr.repository.config.EnableSolrRepositories} would
@@ -45,7 +43,7 @@ import org.springframework.data.solr.repository.support.SolrRepositoryFactoryBea
* @since 1.1.0
*/
@Configuration
@ConditionalOnClass({ SolrServer.class, SolrRepository.class })
@ConditionalOnClass({ SolrClient.class, SolrRepository.class })
@ConditionalOnMissingBean({ SolrRepositoryFactoryBean.class,
SolrRepositoryConfigExtension.class })
@ConditionalOnProperty(prefix = "spring.data.solr.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2016 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,12 +16,13 @@
package org.springframework.boot.autoconfigure.solr;
import java.io.IOException;
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.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -39,35 +40,34 @@ import org.springframework.util.StringUtils;
* @since 1.1.0
*/
@Configuration
@ConditionalOnClass({ HttpSolrServer.class, CloudSolrServer.class,
HashPartitioner.class })
@ConditionalOnClass({HttpSolrClient.class, CloudSolrClient.class})
@EnableConfigurationProperties(SolrProperties.class)
public class SolrAutoConfiguration {
@Autowired
private SolrProperties properties;
private SolrServer solrServer;
private SolrClient solrClient;
@PreDestroy
public void close() {
if (this.solrServer != null) {
this.solrServer.shutdown();
public void close() throws IOException {
if (this.solrClient != null) {
this.solrClient.close();
}
}
@Bean
@ConditionalOnMissingBean
public SolrServer solrServer() {
this.solrServer = createSolrServer();
return this.solrServer;
public SolrClient solrClient() {
this.solrClient = createSolrClient();
return this.solrClient;
}
private SolrServer createSolrServer() {
private SolrClient createSolrClient() {
if (StringUtils.hasText(this.properties.getZkHost())) {
return new CloudSolrServer(this.properties.getZkHost());
return new CloudSolrClient(this.properties.getZkHost());
}
return new HttpSolrServer(this.properties.getHost());
return new HttpSolrClient(this.properties.getHost());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2016 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,8 +16,8 @@
package org.springframework.boot.autoconfigure.data.solr;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.junit.After;
import org.junit.Test;
@@ -54,15 +54,15 @@ public class SolrRepositoriesAutoConfigurationTests {
public void testDefaultRepositoryConfiguration() {
initContext(TestConfiguration.class);
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
assertThat(this.context.getBean(SolrServer.class))
.isInstanceOf(HttpSolrServer.class);
assertThat(this.context.getBean(SolrClient.class))
.isInstanceOf(HttpSolrClient.class);
}
@Test
public void testNoRepositoryConfiguration() {
initContext(EmptyConfiguration.class);
assertThat(this.context.getBean(SolrServer.class))
.isInstanceOf(HttpSolrServer.class);
assertThat(this.context.getBean(SolrClient.class))
.isInstanceOf(HttpSolrClient.class);
}
@Test