Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
e45ef06b
Commit
e45ef06b
authored
May 22, 2014
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish Spring Data Solr integration
parent
6ed69709
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
72 additions
and
91 deletions
+72
-91
SolrRepositoriesAutoConfiguration.java
...autoconfigure/data/SolrRepositoriesAutoConfiguration.java
+4
-3
SolrRepositoriesAutoConfigureRegistrar.java
...onfigure/data/SolrRepositoriesAutoConfigureRegistrar.java
+4
-21
SolrAutoConfiguration.java
...mework/boot/autoconfigure/solr/SolrAutoConfiguration.java
+7
-6
SolrProperties.java
...ringframework/boot/autoconfigure/solr/SolrProperties.java
+5
-4
JpaRepositoriesAutoConfigurationTests.java
...configure/data/JpaRepositoriesAutoConfigurationTests.java
+4
-4
SolrRepositoriesAutoConfigurationTests.java
...onfigure/data/SolrRepositoriesAutoConfigurationTests.java
+13
-11
City.java
...rg/springframework/boot/autoconfigure/data/solr/City.java
+4
-3
CityRepository.java
...ramework/boot/autoconfigure/data/solr/CityRepository.java
+2
-1
pom.xml
spring-boot-dependencies/pom.xml
+5
-0
Product.java
...ple-data-solr/src/main/java/sample/data/solr/Product.java
+8
-11
ProductRepository.java
...olr/src/main/java/sample/data/solr/ProductRepository.java
+1
-4
SampleSolrApplication.java
...src/main/java/sample/data/solr/SampleSolrApplication.java
+7
-10
SampleSolrApplicationTests.java
...est/java/sample/data/solr/SampleSolrApplicationTests.java
+8
-13
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfiguration.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -38,11 +38,12 @@ import org.springframework.data.solr.repository.support.SolrRepositoryFactoryBea
...
@@ -38,11 +38,12 @@ import org.springframework.data.solr.repository.support.SolrRepositoryFactoryBea
* do.
* do.
*
*
* @author Christoph Strobl
* @author Christoph Strobl
* @since 1.1.0
*/
*/
@Configuration
@Configuration
@ConditionalOnClass
({
SolrServer
.
class
,
SolrRepository
.
class
})
@ConditionalOnClass
({
SolrServer
.
class
,
SolrRepository
.
class
})
@ConditionalOnMissingBean
(
SolrRepositoryFactoryBean
.
class
)
@ConditionalOnMissingBean
(
SolrRepositoryFactoryBean
.
class
)
@Import
(
SolrRepositoriesAutoConfigureRegstrar
.
class
)
@Import
(
SolrRepositoriesAutoConfigureReg
i
strar
.
class
)
public
class
SolrRepositoriesAutoConfiguration
{
public
class
SolrRepositoriesAutoConfiguration
{
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigureRegstrar.java
→
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigureReg
i
strar.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -28,38 +28,21 @@ import org.springframework.data.solr.repository.config.SolrRepositoryConfigExten
...
@@ -28,38 +28,21 @@ import org.springframework.data.solr.repository.config.SolrRepositoryConfigExten
* repositories.
* repositories.
*
*
* @author Christoph Strobl
* @author Christoph Strobl
* @since 1.1.0
*/
*/
public
class
SolrRepositoriesAutoConfigureRegstrar
extends
public
class
SolrRepositoriesAutoConfigureReg
i
strar
extends
AbstractRepositoryConfigurationSourceSupport
{
AbstractRepositoryConfigurationSourceSupport
{
/*
* (non-Javadoc)
*
* @see org.springframework.boot.autoconfigure.data.
* AbstractRepositoryConfigurationSourceSupport#getAnnotation()
*/
@Override
@Override
protected
Class
<?
extends
Annotation
>
getAnnotation
()
{
protected
Class
<?
extends
Annotation
>
getAnnotation
()
{
return
EnableSolrRepositories
.
class
;
return
EnableSolrRepositories
.
class
;
}
}
/*
* (non-Javadoc)
*
* @see org.springframework.boot.autoconfigure.data.
* AbstractRepositoryConfigurationSourceSupport#getConfiguration()
*/
@Override
@Override
protected
Class
<?>
getConfiguration
()
{
protected
Class
<?>
getConfiguration
()
{
return
EnableSolrRepositoriesConfiguration
.
class
;
return
EnableSolrRepositoriesConfiguration
.
class
;
}
}
/*
* (non-Javadoc)
*
* @see org.springframework.boot.autoconfigure.data.
* AbstractRepositoryConfigurationSourceSupport#getRepositoryConfigurationExtension()
*/
@Override
@Override
protected
RepositoryConfigurationExtension
getRepositoryConfigurationExtension
()
{
protected
RepositoryConfigurationExtension
getRepositoryConfigurationExtension
()
{
return
new
SolrRepositoryConfigExtension
();
return
new
SolrRepositoryConfigExtension
();
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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;
...
@@ -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.CloudSolrServer
;
import
org.apache.solr.client.solrj.impl.HttpSolrServer
;
import
org.apache.solr.client.solrj.impl.HttpSolrServer
;
import
org.springframework.beans.factory.annotation.Autowired
;
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.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
...
@@ -30,16 +31,18 @@ import org.springframework.context.annotation.Configuration;
...
@@ -30,16 +31,18 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
/**
/**
*
Enables auto configuration for Solr.
*
{@link EnableAutoConfiguration Auto-configuration} for Solr
*
*
* @author Christoph Strobl
* @author Christoph Strobl
* @since 1.1.0
*/
*/
@Configuration
@Configuration
@ConditionalOnClass
(
SolrServer
.
class
)
@ConditionalOnClass
(
SolrServer
.
class
)
@EnableConfigurationProperties
(
SolrProperties
.
class
)
@EnableConfigurationProperties
(
SolrProperties
.
class
)
public
class
SolrAutoConfiguration
{
public
class
SolrAutoConfiguration
{
private
@Autowired
SolrProperties
properties
;
@Autowired
private
SolrProperties
properties
;
private
SolrServer
solrServer
;
private
SolrServer
solrServer
;
...
@@ -53,13 +56,11 @@ public class SolrAutoConfiguration {
...
@@ -53,13 +56,11 @@ public class SolrAutoConfiguration {
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean
public
SolrServer
solrServer
()
{
public
SolrServer
solrServer
()
{
this
.
solrServer
=
createSolrServer
();
this
.
solrServer
=
createSolrServer
();
return
this
.
solrServer
;
return
this
.
solrServer
;
}
}
private
SolrServer
createSolrServer
()
{
private
SolrServer
createSolrServer
()
{
if
(
StringUtils
.
hasText
(
this
.
properties
.
getZkHost
()))
{
if
(
StringUtils
.
hasText
(
this
.
properties
.
getZkHost
()))
{
return
new
CloudSolrServer
(
this
.
properties
.
getZkHost
());
return
new
CloudSolrServer
(
this
.
properties
.
getZkHost
());
}
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrProperties.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -22,6 +22,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
...
@@ -22,6 +22,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* Configuration properties for Solr.
* Configuration properties for Solr.
*
*
* @author Christoph Strobl
* @author Christoph Strobl
* @since 1.1.0
*/
*/
@ConfigurationProperties
(
prefix
=
"spring.data.solr"
)
@ConfigurationProperties
(
prefix
=
"spring.data.solr"
)
public
class
SolrProperties
{
public
class
SolrProperties
{
...
@@ -31,7 +32,7 @@ public class SolrProperties {
...
@@ -31,7 +32,7 @@ public class SolrProperties {
private
String
zkHost
;
private
String
zkHost
;
public
String
getHost
()
{
public
String
getHost
()
{
return
host
;
return
this
.
host
;
}
}
public
void
setHost
(
String
host
)
{
public
void
setHost
(
String
host
)
{
...
@@ -39,7 +40,7 @@ public class SolrProperties {
...
@@ -39,7 +40,7 @@ public class SolrProperties {
}
}
public
String
getZkHost
()
{
public
String
getZkHost
()
{
return
zkHost
;
return
this
.
zkHost
;
}
}
public
void
setZkHost
(
String
zkHost
)
{
public
void
setZkHost
(
String
zkHost
)
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java
View file @
e45ef06b
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigurationTests.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -15,10 +15,6 @@
...
@@ -15,10 +15,6 @@
*/
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
data
;
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.SolrServer
;
import
org.apache.solr.client.solrj.impl.HttpSolrServer
;
import
org.apache.solr.client.solrj.impl.HttpSolrServer
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -32,7 +28,13 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
...
@@ -32,7 +28,13 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.solr.repository.config.EnableSolrRepositories
;
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
* @author Christoph Strobl
*/
*/
public
class
SolrRepositoriesAutoConfigurationTests
{
public
class
SolrRepositoriesAutoConfigurationTests
{
...
@@ -41,23 +43,22 @@ public class SolrRepositoriesAutoConfigurationTests {
...
@@ -41,23 +43,22 @@ public class SolrRepositoriesAutoConfigurationTests {
@Test
@Test
public
void
testDefaultRepositoryConfiguration
()
{
public
void
testDefaultRepositoryConfiguration
()
{
initContext
(
TestConfiguration
.
class
);
initContext
(
TestConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
CityRepository
.
class
),
notNullValue
());
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
@Test
public
void
testNoRepositoryConfiguration
()
{
public
void
testNoRepositoryConfiguration
()
{
initContext
(
EmptyConfiguration
.
class
);
initContext
(
EmptyConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
SolrServer
.
class
),
instanceOf
(
HttpSolrServer
.
class
));
assertThat
(
this
.
context
.
getBean
(
SolrServer
.
class
),
instanceOf
(
HttpSolrServer
.
class
));
}
}
@Test
@Test
public
void
doesNotTriggerDefaultRepositoryDetectionIfCustomized
()
{
public
void
doesNotTriggerDefaultRepositoryDetectionIfCustomized
()
{
initContext
(
CustomizedConfiguration
.
class
);
initContext
(
CustomizedConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
CitySolrRepository
.
class
),
notNullValue
());
assertThat
(
this
.
context
.
getBean
(
CitySolrRepository
.
class
),
notNullValue
());
}
}
...
@@ -65,7 +66,8 @@ public class SolrRepositoriesAutoConfigurationTests {
...
@@ -65,7 +66,8 @@ public class SolrRepositoriesAutoConfigurationTests {
private
void
initContext
(
Class
<?>
configClass
)
{
private
void
initContext
(
Class
<?>
configClass
)
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
register
(
configClass
,
SolrAutoConfiguration
.
class
,
SolrRepositoriesAutoConfiguration
.
class
,
this
.
context
.
register
(
configClass
,
SolrAutoConfiguration
.
class
,
SolrRepositoriesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/City.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
solr
;
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
solr
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
...
@@ -29,7 +30,7 @@ public class City {
...
@@ -29,7 +30,7 @@ public class City {
private
@Indexed
String
name
;
private
@Indexed
String
name
;
public
String
getId
()
{
public
String
getId
()
{
return
id
;
return
this
.
id
;
}
}
public
void
setId
(
String
id
)
{
public
void
setId
(
String
id
)
{
...
@@ -37,7 +38,7 @@ public class City {
...
@@ -37,7 +38,7 @@ public class City {
}
}
public
String
getName
()
{
public
String
getName
()
{
return
name
;
return
this
.
name
;
}
}
public
void
setName
(
String
name
)
{
public
void
setName
(
String
name
)
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/CityRepository.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
solr
;
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
solr
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
...
...
spring-boot-dependencies/pom.xml
View file @
e45ef06b
...
@@ -192,6 +192,11 @@
...
@@ -192,6 +192,11 @@
<artifactId>
spring-boot-starter-data-rest
</artifactId>
<artifactId>
spring-boot-starter-data-rest
</artifactId>
<version>
1.1.0.BUILD-SNAPSHOT
</version>
<version>
1.1.0.BUILD-SNAPSHOT
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-solr
</artifactId>
<version>
1.1.0.BUILD-SNAPSHOT
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-freemarker
</artifactId>
<artifactId>
spring-boot-starter-freemarker
</artifactId>
...
...
spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -23,9 +23,6 @@ import org.springframework.data.annotation.Id;
...
@@ -23,9 +23,6 @@ import org.springframework.data.annotation.Id;
import
org.springframework.data.solr.core.geo.Point
;
import
org.springframework.data.solr.core.geo.Point
;
import
org.springframework.data.solr.core.mapping.SolrDocument
;
import
org.springframework.data.solr.core.mapping.SolrDocument
;
/**
* @author Christoph Strobl
*/
@SolrDocument
(
solrCoreName
=
"collection1"
)
@SolrDocument
(
solrCoreName
=
"collection1"
)
public
class
Product
{
public
class
Product
{
...
@@ -55,7 +52,7 @@ public class Product {
...
@@ -55,7 +52,7 @@ public class Product {
}
}
public
String
getId
()
{
public
String
getId
()
{
return
id
;
return
this
.
id
;
}
}
public
void
setId
(
String
id
)
{
public
void
setId
(
String
id
)
{
...
@@ -63,7 +60,7 @@ public class Product {
...
@@ -63,7 +60,7 @@ public class Product {
}
}
public
String
getName
()
{
public
String
getName
()
{
return
name
;
return
this
.
name
;
}
}
public
void
setName
(
String
name
)
{
public
void
setName
(
String
name
)
{
...
@@ -71,7 +68,7 @@ public class Product {
...
@@ -71,7 +68,7 @@ public class Product {
}
}
public
Double
getPrice
()
{
public
Double
getPrice
()
{
return
price
;
return
this
.
price
;
}
}
public
void
setPrice
(
Double
price
)
{
public
void
setPrice
(
Double
price
)
{
...
@@ -79,7 +76,7 @@ public class Product {
...
@@ -79,7 +76,7 @@ public class Product {
}
}
public
List
<
String
>
getCategory
()
{
public
List
<
String
>
getCategory
()
{
return
category
;
return
this
.
category
;
}
}
public
void
setCategory
(
List
<
String
>
category
)
{
public
void
setCategory
(
List
<
String
>
category
)
{
...
@@ -87,7 +84,7 @@ public class Product {
...
@@ -87,7 +84,7 @@ public class Product {
}
}
public
Point
getLocation
()
{
public
Point
getLocation
()
{
return
location
;
return
this
.
location
;
}
}
public
void
setLocation
(
Point
location
)
{
public
void
setLocation
(
Point
location
)
{
...
@@ -96,8 +93,8 @@ public class Product {
...
@@ -96,8 +93,8 @@ public class Product {
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Product [id="
+
id
+
", name="
+
name
+
", price="
+
price
return
"Product [id="
+
this
.
id
+
", name="
+
this
.
name
+
", price="
+
this
.
price
+
", category="
+
category
+
", location="
+
location
+
"]"
;
+
", category="
+
this
.
category
+
", location="
+
this
.
location
+
"]"
;
}
}
}
}
spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/ProductRepository.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -20,9 +20,6 @@ import java.util.List;
...
@@ -20,9 +20,6 @@ import java.util.List;
import
org.springframework.data.solr.repository.SolrCrudRepository
;
import
org.springframework.data.solr.repository.SolrCrudRepository
;
/**
* @author Christoph Strobl
*/
public
interface
ProductRepository
extends
SolrCrudRepository
<
Product
,
String
>
{
public
interface
ProductRepository
extends
SolrCrudRepository
<
Product
,
String
>
{
List
<
Product
>
findByNameStartingWith
(
String
name
);
List
<
Product
>
findByNameStartingWith
(
String
name
);
...
...
spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/SampleSolrApplication.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -23,9 +23,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
...
@@ -23,9 +23,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author Christoph Strobl
*/
@Configuration
@Configuration
@EnableAutoConfiguration
@EnableAutoConfiguration
@ComponentScan
@ComponentScan
...
@@ -37,17 +34,17 @@ public class SampleSolrApplication implements CommandLineRunner {
...
@@ -37,17 +34,17 @@ public class SampleSolrApplication implements CommandLineRunner {
@Override
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
public
void
run
(
String
...
args
)
throws
Exception
{
repository
.
deleteAll
();
this
.
repository
.
deleteAll
();
// insert some products
// insert some products
repository
.
save
(
new
Product
(
"1"
,
"Nintendo Entertainment System"
));
this
.
repository
.
save
(
new
Product
(
"1"
,
"Nintendo Entertainment System"
));
repository
.
save
(
new
Product
(
"2"
,
"Sega Megadrive"
));
this
.
repository
.
save
(
new
Product
(
"2"
,
"Sega Megadrive"
));
repository
.
save
(
new
Product
(
"3"
,
"Sony Playstation"
));
this
.
repository
.
save
(
new
Product
(
"3"
,
"Sony Playstation"
));
// fetch all
// fetch all
System
.
out
.
println
(
"Products found by findAll():"
);
System
.
out
.
println
(
"Products found by findAll():"
);
System
.
out
.
println
(
"----------------------------"
);
System
.
out
.
println
(
"----------------------------"
);
for
(
Product
product
:
repository
.
findAll
())
{
for
(
Product
product
:
this
.
repository
.
findAll
())
{
System
.
out
.
println
(
product
);
System
.
out
.
println
(
product
);
}
}
System
.
out
.
println
();
System
.
out
.
println
();
...
@@ -55,7 +52,7 @@ public class SampleSolrApplication implements CommandLineRunner {
...
@@ -55,7 +52,7 @@ public class SampleSolrApplication implements CommandLineRunner {
// fetch a single product
// fetch a single product
System
.
out
.
println
(
"Products founds with findByNameStartingWith('So'):"
);
System
.
out
.
println
(
"Products founds with findByNameStartingWith('So'):"
);
System
.
out
.
println
(
"--------------------------------"
);
System
.
out
.
println
(
"--------------------------------"
);
for
(
Product
product
:
repository
.
findByNameStartingWith
(
"So"
))
{
for
(
Product
product
:
this
.
repository
.
findByNameStartingWith
(
"So"
))
{
System
.
out
.
println
(
product
);
System
.
out
.
println
(
product
);
}
}
System
.
out
.
println
();
System
.
out
.
println
();
...
...
spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java
View file @
e45ef06b
/*
/*
* Copyright 2014 the original author or authors.
* Copyright 201
2-201
4 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,17 +16,13 @@
...
@@ -16,17 +16,13 @@
package
sample
.
data
.
solr
;
package
sample
.
data
.
solr
;
import
static
org
.
junit
.
Assert
.*;
import
org.apache.solr.client.solrj.SolrServerException
;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.test.OutputCapture
;
import
org.springframework.boot.test.OutputCapture
;
import
org.springframework.core.NestedCheckedException
;
import
org.springframework.core.NestedCheckedException
;
/**
import
static
org
.
junit
.
Assert
.
assertTrue
;
* @author Christoph Strobl
*/
public
class
SampleSolrApplicationTests
{
public
class
SampleSolrApplicationTests
{
@Rule
@Rule
...
@@ -37,7 +33,8 @@ public class SampleSolrApplicationTests {
...
@@ -37,7 +33,8 @@ public class SampleSolrApplicationTests {
try
{
try
{
SampleSolrApplication
.
main
(
new
String
[
0
]);
SampleSolrApplication
.
main
(
new
String
[
0
]);
}
catch
(
IllegalStateException
ex
)
{
}
catch
(
IllegalStateException
ex
)
{
if
(
serverNotRunning
(
ex
))
{
if
(
serverNotRunning
(
ex
))
{
return
;
return
;
}
}
...
@@ -51,12 +48,10 @@ public class SampleSolrApplicationTests {
...
@@ -51,12 +48,10 @@ public class SampleSolrApplicationTests {
@SuppressWarnings
(
"serial"
)
@SuppressWarnings
(
"serial"
)
NestedCheckedException
nested
=
new
NestedCheckedException
(
"failed"
,
ex
)
{
NestedCheckedException
nested
=
new
NestedCheckedException
(
"failed"
,
ex
)
{
};
};
if
(
nested
.
contains
(
SolrServerException
.
class
))
{
Throwable
root
=
nested
.
getRootCause
();
Throwable
root
=
nested
.
getRootCause
();
if
(
root
.
getMessage
().
contains
(
"Connection refused"
))
{
if
(
root
.
getMessage
().
contains
(
"Connection refused"
))
{
return
true
;
return
true
;
}
}
}
return
false
;
return
false
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment