parent
1c365662b0
commit
b205e02e33
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2015 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.
|
||||
|
|
@ -23,7 +23,7 @@ import javax.jms.ConnectionFactory;
|
|||
import javax.sql.DataSource;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.client.solrj.SolrClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
|
|
@ -269,18 +269,18 @@ public class HealthIndicatorAutoConfiguration {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnBean(SolrServer.class)
|
||||
@ConditionalOnBean(SolrClient.class)
|
||||
@ConditionalOnEnabledHealthIndicator("solr")
|
||||
public static class SolrHealthIndicatorConfiguration extends
|
||||
CompositeHealthIndicatorConfiguration<SolrHealthIndicator, SolrServer> {
|
||||
CompositeHealthIndicatorConfiguration<SolrHealthIndicator, SolrClient> {
|
||||
|
||||
@Autowired
|
||||
private Map<String, SolrServer> solrServers;
|
||||
private Map<String, SolrClient> solrClients;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "solrHealthIndicator")
|
||||
public HealthIndicator solrHealthIndicator() {
|
||||
return createHealthIndicator(this.solrServers);
|
||||
return createHealthIndicator(this.solrClients);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.actuate.health;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.client.solrj.SolrClient;
|
||||
|
||||
/**
|
||||
* {@link HealthIndicator} for Apache Solr.
|
||||
|
|
@ -26,15 +26,15 @@ import org.apache.solr.client.solrj.SolrServer;
|
|||
*/
|
||||
public class SolrHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
private final SolrServer solrServer;
|
||||
private final SolrClient solrClient;
|
||||
|
||||
public SolrHealthIndicator(SolrServer solrServer) {
|
||||
this.solrServer = solrServer;
|
||||
public SolrHealthIndicator(SolrClient solrClient) {
|
||||
this.solrClient = solrClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
Object status = this.solrServer.ping().getResponse().get("status");
|
||||
Object status = this.solrClient.ping().getResponse().get("status");
|
||||
builder.up().withDetail("solrStatus", status);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -18,7 +18,7 @@ package org.springframework.boot.actuate.health;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.client.solrj.SolrClient;
|
||||
import org.apache.solr.client.solrj.response.SolrPingResponse;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.junit.After;
|
||||
|
|
@ -55,7 +55,7 @@ public class SolrHealthIndicatorTests {
|
|||
this.context = new AnnotationConfigApplicationContext(
|
||||
PropertyPlaceholderAutoConfiguration.class, SolrAutoConfiguration.class,
|
||||
EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
|
||||
assertThat(this.context.getBeanNamesForType(SolrServer.class).length)
|
||||
assertThat(this.context.getBeanNamesForType(SolrClient.class).length)
|
||||
.isEqualTo(1);
|
||||
SolrHealthIndicator healthIndicator = this.context
|
||||
.getBean(SolrHealthIndicator.class);
|
||||
|
|
@ -64,13 +64,13 @@ public class SolrHealthIndicatorTests {
|
|||
|
||||
@Test
|
||||
public void solrIsUp() throws Exception {
|
||||
SolrServer solrServer = mock(SolrServer.class);
|
||||
SolrClient solrClient = mock(SolrClient.class);
|
||||
SolrPingResponse pingResponse = new SolrPingResponse();
|
||||
NamedList<Object> response = new NamedList<Object>();
|
||||
response.add("status", "OK");
|
||||
pingResponse.setResponse(response);
|
||||
given(solrServer.ping()).willReturn(pingResponse);
|
||||
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrServer);
|
||||
given(solrClient.ping()).willReturn(pingResponse);
|
||||
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
|
||||
Health health = healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails().get("solrStatus")).isEqualTo("OK");
|
||||
|
|
@ -78,9 +78,9 @@ public class SolrHealthIndicatorTests {
|
|||
|
||||
@Test
|
||||
public void solrIsDown() throws Exception {
|
||||
SolrServer solrServer = mock(SolrServer.class);
|
||||
given(solrServer.ping()).willThrow(new IOException("Connection failed"));
|
||||
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrServer);
|
||||
SolrClient solrClient = mock(SolrClient.class);
|
||||
given(solrClient.ping()).willThrow(new IOException("Connection failed"));
|
||||
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
|
||||
Health health = healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat(((String) health.getDetails().get("error"))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@
|
|||
<flyway.version>3.2.1</flyway.version>
|
||||
<freemarker.version>2.3.23</freemarker.version>
|
||||
<elasticsearch.version>1.5.2</elasticsearch.version>
|
||||
<gemfire.version>8.1.0</gemfire.version>
|
||||
<gemfire.version>8.2.0</gemfire.version>
|
||||
<glassfish-el.version>3.0.0</glassfish-el.version>
|
||||
<gradle.version>1.12</gradle.version>
|
||||
<groovy.version>2.4.4</groovy.version>
|
||||
|
|
@ -124,13 +124,13 @@
|
|||
<simple-json.version>1.1.1</simple-json.version>
|
||||
<slf4j.version>1.7.15</slf4j.version>
|
||||
<snakeyaml.version>1.16</snakeyaml.version>
|
||||
<solr.version>4.10.4</solr.version>
|
||||
<solr.version>5.3.1</solr.version>
|
||||
<spock.version>1.0-groovy-2.4</spock.version>
|
||||
<spring.version>4.2.4.RELEASE</spring.version>
|
||||
<spring-amqp.version>1.5.3.RELEASE</spring-amqp.version>
|
||||
<spring-cloud-connectors.version>1.2.1.RELEASE</spring-cloud-connectors.version>
|
||||
<spring-batch.version>3.0.6.RELEASE</spring-batch.version>
|
||||
<spring-data-releasetrain.version>Gosling-SR2A</spring-data-releasetrain.version>
|
||||
<spring-data-releasetrain.version>Hopper-M1</spring-data-releasetrain.version>
|
||||
<spring-hateoas.version>0.19.0.RELEASE</spring-hateoas.version>
|
||||
<spring-integration.version>4.2.4.RELEASE</spring-integration.version>
|
||||
<spring-loaded.version>1.2.5.RELEASE</spring-loaded.version>
|
||||
|
|
|
|||
|
|
@ -2961,19 +2961,15 @@ 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 4 client library and abstractions on top of it provided by
|
||||
auto-configuration for the Solr 5 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]]
|
||||
==== Connecting to Solr
|
||||
You can inject an auto-configured `SolrServer` instance as you would any other Spring
|
||||
You can inject an auto-configured `SolrClient` instance as you would any other Spring
|
||||
bean. By default the instance will attempt to connect to a server using
|
||||
`http://localhost:8983/solr`:
|
||||
|
||||
|
|
@ -2982,10 +2978,10 @@ bean. By default the instance will attempt to connect to a server using
|
|||
@Component
|
||||
public class MyBean {
|
||||
|
||||
private SolrServer solr;
|
||||
private SolrClient solr;
|
||||
|
||||
@Autowired
|
||||
public MyBean(SolrServer solr) {
|
||||
public MyBean(SolrClient solr) {
|
||||
this.solr = solr;
|
||||
}
|
||||
|
||||
|
|
@ -2994,7 +2990,7 @@ bean. By default the instance will attempt to connect to a server using
|
|||
}
|
||||
----
|
||||
|
||||
If you add a `@Bean` of your own of type `SolrServer` it will replace the default.
|
||||
If you add a `@Bean` of your own of type `SolrClient` it will replace the default.
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@
|
|||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-gemfire</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
|
|
|||
Loading…
Reference in New Issue