Skip to content

Commit e45ef06

Browse files
committed
Polish Spring Data Solr integration
1 parent 6ed6970 commit e45ef06

File tree

13 files changed

+72
-91
lines changed

13 files changed

+72
-91
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfiguration.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,13 +36,14 @@
3636
* If active auto configuration does the same as
3737
* {@link org.springframework.data.solr.repository.config.EnableSolrRepositories} would
3838
* do.
39-
*
39+
*
4040
* @author Christoph Strobl
41+
* @since 1.1.0
4142
*/
4243
@Configuration
4344
@ConditionalOnClass({ SolrServer.class, SolrRepository.class })
4445
@ConditionalOnMissingBean(SolrRepositoryFactoryBean.class)
45-
@Import(SolrRepositoriesAutoConfigureRegstrar.class)
46+
@Import(SolrRepositoriesAutoConfigureRegistrar.class)
4647
public class SolrRepositoriesAutoConfiguration {
4748

4849
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,40 +26,23 @@
2626
/**
2727
* {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Solr
2828
* repositories.
29-
*
29+
*
3030
* @author Christoph Strobl
31+
* @since 1.1.0
3132
*/
32-
public class SolrRepositoriesAutoConfigureRegstrar extends
33+
public class SolrRepositoriesAutoConfigureRegistrar extends
3334
AbstractRepositoryConfigurationSourceSupport {
3435

35-
/*
36-
* (non-Javadoc)
37-
*
38-
* @see org.springframework.boot.autoconfigure.data.
39-
* AbstractRepositoryConfigurationSourceSupport#getAnnotation()
40-
*/
4136
@Override
4237
protected Class<? extends Annotation> getAnnotation() {
4338
return EnableSolrRepositories.class;
4439
}
4540

46-
/*
47-
* (non-Javadoc)
48-
*
49-
* @see org.springframework.boot.autoconfigure.data.
50-
* AbstractRepositoryConfigurationSourceSupport#getConfiguration()
51-
*/
5241
@Override
5342
protected Class<?> getConfiguration() {
5443
return EnableSolrRepositoriesConfiguration.class;
5544
}
5645

57-
/*
58-
* (non-Javadoc)
59-
*
60-
* @see org.springframework.boot.autoconfigure.data.
61-
* AbstractRepositoryConfigurationSourceSupport#getRepositoryConfigurationExtension()
62-
*/
6346
@Override
6447
protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() {
6548
return new SolrRepositoryConfigExtension();

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222
import org.apache.solr.client.solrj.impl.CloudSolrServer;
2323
import org.apache.solr.client.solrj.impl.HttpSolrServer;
2424
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2627
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2728
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -30,16 +31,18 @@
3031
import org.springframework.util.StringUtils;
3132

3233
/**
33-
* Enables auto configuration for Solr.
34-
*
34+
* {@link EnableAutoConfiguration Auto-configuration} for Solr
35+
*
3536
* @author Christoph Strobl
37+
* @since 1.1.0
3638
*/
3739
@Configuration
3840
@ConditionalOnClass(SolrServer.class)
3941
@EnableConfigurationProperties(SolrProperties.class)
4042
public class SolrAutoConfiguration {
4143

42-
private @Autowired SolrProperties properties;
44+
@Autowired
45+
private SolrProperties properties;
4346

4447
private SolrServer solrServer;
4548

@@ -53,13 +56,11 @@ public void close() {
5356
@Bean
5457
@ConditionalOnMissingBean
5558
public SolrServer solrServer() {
56-
5759
this.solrServer = createSolrServer();
5860
return this.solrServer;
5961
}
6062

6163
private SolrServer createSolrServer() {
62-
6364
if (StringUtils.hasText(this.properties.getZkHost())) {
6465
return new CloudSolrServer(this.properties.getZkHost());
6566
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrProperties.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,9 @@
2020

2121
/**
2222
* Configuration properties for Solr.
23-
*
23+
*
2424
* @author Christoph Strobl
25+
* @since 1.1.0
2526
*/
2627
@ConfigurationProperties(prefix = "spring.data.solr")
2728
public class SolrProperties {
@@ -31,15 +32,15 @@ public class SolrProperties {
3132
private String zkHost;
3233

3334
public String getHost() {
34-
return host;
35+
return this.host;
3536
}
3637

3738
public void setHost(String host) {
3839
this.host = host;
3940
}
4041

4142
public String getZkHost() {
42-
return zkHost;
43+
return this.zkHost;
4344
}
4445

4546
public void setZkHost(String zkHost) {

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
/**
4040
* Tests for {@link JpaRepositoriesAutoConfiguration}.
41-
*
41+
*
4242
* @author Dave Syer
4343
* @author Oliver Gierke
4444
*/
@@ -83,9 +83,9 @@ protected static class TestConfiguration {
8383

8484
@Configuration
8585
@EnableJpaRepositories(basePackageClasses = org.springframework.boot.autoconfigure.data.alt.CityJpaRepository.class, excludeFilters = {
86-
@Filter(type = FilterType.ASSIGNABLE_TYPE, value = CityMongoDbRepository.class),
87-
@Filter(type = FilterType.ASSIGNABLE_TYPE, value = CitySolrRepository.class) })
88-
@TestAutoConfigurationPackage(City.class)
86+
@Filter(type = FilterType.ASSIGNABLE_TYPE, value = CityMongoDbRepository.class),
87+
@Filter(type = FilterType.ASSIGNABLE_TYPE, value = CitySolrRepository.class) })
88+
@TestAutoConfigurationPackage(City.class)
8989
protected static class CustomConfiguration {
9090

9191
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigurationTests.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,10 +15,6 @@
1515
*/
1616
package org.springframework.boot.autoconfigure.data;
1717

18-
import static org.hamcrest.core.IsInstanceOf.*;
19-
import static org.hamcrest.core.IsNull.*;
20-
import static org.junit.Assert.*;
21-
2218
import org.apache.solr.client.solrj.SolrServer;
2319
import org.apache.solr.client.solrj.impl.HttpSolrServer;
2420
import org.junit.Test;
@@ -32,7 +28,13 @@
3228
import org.springframework.context.annotation.Configuration;
3329
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
3430

31+
import static org.hamcrest.core.IsInstanceOf.instanceOf;
32+
import static org.hamcrest.core.IsNull.notNullValue;
33+
import static org.junit.Assert.assertThat;
34+
3535
/**
36+
* Tests for {@link SolrRepositoriesAutoConfiguration}
37+
*
3638
* @author Christoph Strobl
3739
*/
3840
public class SolrRepositoriesAutoConfigurationTests {
@@ -41,31 +43,31 @@ public class SolrRepositoriesAutoConfigurationTests {
4143

4244
@Test
4345
public void testDefaultRepositoryConfiguration() {
44-
4546
initContext(TestConfiguration.class);
4647

4748
assertThat(this.context.getBean(CityRepository.class), notNullValue());
48-
assertThat(this.context.getBean(SolrServer.class), instanceOf(HttpSolrServer.class));
49+
assertThat(this.context.getBean(SolrServer.class),
50+
instanceOf(HttpSolrServer.class));
4951
}
5052

5153
@Test
5254
public void testNoRepositoryConfiguration() {
53-
5455
initContext(EmptyConfiguration.class);
55-
assertThat(this.context.getBean(SolrServer.class), instanceOf(HttpSolrServer.class));
56+
assertThat(this.context.getBean(SolrServer.class),
57+
instanceOf(HttpSolrServer.class));
5658
}
5759

5860
@Test
5961
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
60-
6162
initContext(CustomizedConfiguration.class);
6263
assertThat(this.context.getBean(CitySolrRepository.class), notNullValue());
6364
}
6465

6566
private void initContext(Class<?> configClass) {
6667

6768
this.context = new AnnotationConfigApplicationContext();
68-
this.context.register(configClass, SolrAutoConfiguration.class, SolrRepositoriesAutoConfiguration.class,
69+
this.context.register(configClass, SolrAutoConfiguration.class,
70+
SolrRepositoriesAutoConfiguration.class,
6971
PropertyPlaceholderAutoConfiguration.class);
7072
this.context.refresh();
7173
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/City.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.boot.autoconfigure.data.solr;
1718

1819
import org.springframework.data.annotation.Id;
@@ -29,15 +30,15 @@ public class City {
2930
private @Indexed String name;
3031

3132
public String getId() {
32-
return id;
33+
return this.id;
3334
}
3435

3536
public void setId(String id) {
3637
this.id = id;
3738
}
3839

3940
public String getName() {
40-
return name;
41+
return this.name;
4142
}
4243

4344
public void setName(String name) {

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/CityRepository.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.boot.autoconfigure.data.solr;
1718

1819
import org.springframework.data.domain.Page;

spring-boot-dependencies/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@
192192
<artifactId>spring-boot-starter-data-rest</artifactId>
193193
<version>1.1.0.BUILD-SNAPSHOT</version>
194194
</dependency>
195+
<dependency>
196+
<groupId>org.springframework.boot</groupId>
197+
<artifactId>spring-boot-starter-data-solr</artifactId>
198+
<version>1.1.0.BUILD-SNAPSHOT</version>
199+
</dependency>
195200
<dependency>
196201
<groupId>org.springframework.boot</groupId>
197202
<artifactId>spring-boot-starter-freemarker</artifactId>

spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,9 +23,6 @@
2323
import org.springframework.data.solr.core.geo.Point;
2424
import org.springframework.data.solr.core.mapping.SolrDocument;
2525

26-
/**
27-
* @author Christoph Strobl
28-
*/
2926
@SolrDocument(solrCoreName = "collection1")
3027
public class Product {
3128

@@ -55,39 +52,39 @@ public Product(String id, String name) {
5552
}
5653

5754
public String getId() {
58-
return id;
55+
return this.id;
5956
}
6057

6158
public void setId(String id) {
6259
this.id = id;
6360
}
6461

6562
public String getName() {
66-
return name;
63+
return this.name;
6764
}
6865

6966
public void setName(String name) {
7067
this.name = name;
7168
}
7269

7370
public Double getPrice() {
74-
return price;
71+
return this.price;
7572
}
7673

7774
public void setPrice(Double price) {
7875
this.price = price;
7976
}
8077

8178
public List<String> getCategory() {
82-
return category;
79+
return this.category;
8380
}
8481

8582
public void setCategory(List<String> category) {
8683
this.category = category;
8784
}
8885

8986
public Point getLocation() {
90-
return location;
87+
return this.location;
9188
}
9289

9390
public void setLocation(Point location) {
@@ -96,8 +93,8 @@ public void setLocation(Point location) {
9693

9794
@Override
9895
public String toString() {
99-
return "Product [id=" + id + ", name=" + name + ", price=" + price
100-
+ ", category=" + category + ", location=" + location + "]";
96+
return "Product [id=" + this.id + ", name=" + this.name + ", price=" + this.price
97+
+ ", category=" + this.category + ", location=" + this.location + "]";
10198
}
10299

103100
}

0 commit comments

Comments
 (0)