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
99940337
Commit
99940337
authored
Jun 01, 2014
by
Artur Konczak
Committed by
Phillip Webb
Jun 01, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for Elasticsearch
Add auto-configuration and starters for Elasticsearch. Fixes gh-408
parent
b3129524
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
627 additions
and
0 deletions
+627
-0
pom.xml
spring-boot-autoconfigure/pom.xml
+5
-0
ElasticsearchRepositoriesAutoConfiguration.java
...gure/data/ElasticsearchRepositoriesAutoConfiguration.java
+44
-0
ElasticsearchRepositoriesAutoConfigureRegistrar.java
...data/ElasticsearchRepositoriesAutoConfigureRegistrar.java
+57
-0
ElasticsearchAutoConfiguration.java
...nfigure/elasticsearch/ElasticsearchAutoConfiguration.java
+74
-0
ElasticsearchDataAutoConfiguration.java
...ure/elasticsearch/ElasticsearchDataAutoConfiguration.java
+52
-0
ElasticsearchProperties.java
.../autoconfigure/elasticsearch/ElasticsearchProperties.java
+82
-0
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+3
-0
pom.xml
spring-boot-dependencies/pom.xml
+5
-0
pom.xml
spring-boot-samples/pom.xml
+1
-0
.gitignore
...-samples/spring-boot-sample-data-elasticsearch/.gitignore
+1
-0
pom.xml
...oot-samples/spring-boot-sample-data-elasticsearch/pom.xml
+39
-0
Customer.java
...rch/src/main/java/sample/data/elasticsearch/Customer.java
+70
-0
CustomerRepository.java
...in/java/sample/data/elasticsearch/CustomerRepository.java
+29
-0
SampleElasticsearchApplication.java
...le/data/elasticsearch/SampleElasticsearchApplication.java
+71
-0
SampleElasticsearchApplicationTests.java
...ta/elasticsearch/SampleElasticsearchApplicationTests.java
+66
-0
pom.xml
spring-boot-starters/pom.xml
+1
-0
pom.xml
...t-starters/spring-boot-starter-data-elasticsearch/pom.xml
+26
-0
spring.provides
...elasticsearch/src/main/resources/META-INF/spring.provides
+1
-0
No files found.
spring-boot-autoconfigure/pom.xml
View file @
99940337
...
...
@@ -186,6 +186,11 @@
<artifactId>
spring-data-redis
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-elasticsearch
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-solr
</artifactId>
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfiguration.java
0 → 100644
View file @
99940337
/*
* Copyright 2012-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
data
;
import
org.elasticsearch.client.Client
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.data.elasticsearch.repository.ElasticsearchRepository
;
import
org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories
;
import
org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Elasticsearch
* Repositories.
*
* @author Artur Konczak
* @author Mohsin Husen
* @see EnableElasticsearchRepositories
* @since 1.1.0
*/
@Configuration
@ConditionalOnClass
({
Client
.
class
,
ElasticsearchRepository
.
class
})
@ConditionalOnMissingBean
(
ElasticsearchRepositoryFactoryBean
.
class
)
@Import
(
ElasticsearchRepositoriesAutoConfigureRegistrar
.
class
)
public
class
ElasticsearchRepositoriesAutoConfiguration
{
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfigureRegistrar.java
0 → 100644
View file @
99940337
/*
* Copyright 2012-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
data
;
import
java.lang.annotation.Annotation
;
import
org.springframework.context.annotation.ImportBeanDefinitionRegistrar
;
import
org.springframework.data.elasticsearch.repository.config.ElasticsearchRepositoryConfigExtension
;
import
org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories
;
import
org.springframework.data.repository.config.RepositoryConfigurationExtension
;
/**
* {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Elasticsearch
* Repositories.
*
* @author Artur Konczak
* @author Mohsin Husen
* @since 1.1.0
*/
class
ElasticsearchRepositoriesAutoConfigureRegistrar
extends
AbstractRepositoryConfigurationSourceSupport
{
@Override
protected
Class
<?
extends
Annotation
>
getAnnotation
()
{
return
EnableElasticsearchRepositories
.
class
;
}
@Override
protected
Class
<?>
getConfiguration
()
{
return
EnableElasticsearchRepositoriesConfiguration
.
class
;
}
@Override
protected
RepositoryConfigurationExtension
getRepositoryConfigurationExtension
()
{
return
new
ElasticsearchRepositoryConfigExtension
();
}
@EnableElasticsearchRepositories
private
static
class
EnableElasticsearchRepositoriesConfiguration
{
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java
0 → 100644
View file @
99940337
/*
* Copyright 2012-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
elasticsearch
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.elasticsearch.client.Client
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} for Elasticsearch.
*
* @author Artur Konczak
* @author Mohsin Husen
* @since 1.1.0
*/
@Configuration
@ConditionalOnClass
(
Client
.
class
)
@EnableConfigurationProperties
(
ElasticsearchProperties
.
class
)
public
class
ElasticsearchAutoConfiguration
implements
DisposableBean
{
private
static
Log
logger
=
LogFactory
.
getLog
(
ElasticsearchAutoConfiguration
.
class
);
@Autowired
private
ElasticsearchProperties
properties
;
private
Client
client
;
@Bean
public
Client
elasticsearchClient
()
{
this
.
client
=
this
.
properties
.
createClient
();
return
this
.
client
;
}
@Override
public
void
destroy
()
throws
Exception
{
if
(
this
.
client
!=
null
)
{
try
{
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"Closing Elasticsearch client"
);
}
if
(
this
.
client
!=
null
)
{
this
.
client
.
close
();
}
}
catch
(
final
Exception
ex
)
{
if
(
logger
.
isErrorEnabled
())
{
logger
.
error
(
"Error closing Elasticsearch client: "
,
ex
);
}
}
}
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchDataAutoConfiguration.java
0 → 100644
View file @
99940337
/*
* Copyright 2012-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
elasticsearch
;
import
org.elasticsearch.client.Client
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.elasticsearch.core.ElasticsearchTemplate
;
import
org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Elasticsearch
* support.
* <p>
* Registers a {@link ElasticsearchTemplate} if no other bean of the same type is
* configured.
*
* @author Artur Konczak
* @author Mohsin Husen
* @see EnableElasticsearchRepositories
* @since 1.1.0
*/
@Configuration
@ConditionalOnClass
({
Client
.
class
,
ElasticsearchTemplate
.
class
})
@AutoConfigureAfter
(
ElasticsearchAutoConfiguration
.
class
)
public
class
ElasticsearchDataAutoConfiguration
{
@Bean
@ConditionalOnMissingBean
public
ElasticsearchTemplate
elasticsearchTemplate
(
Client
client
)
{
return
new
ElasticsearchTemplate
(
client
);
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java
0 → 100644
View file @
99940337
/*
* Copyright 2012-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
elasticsearch
;
import
org.elasticsearch.client.Client
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.data.elasticsearch.client.NodeClientFactoryBean
;
import
org.springframework.data.elasticsearch.client.TransportClientFactoryBean
;
import
org.springframework.util.StringUtils
;
/**
* Configuration properties for Elasticsearch.
*
* @author Artur Konczak
* @author Mohsin Husen
* @since 1.1.0
*/
@ConfigurationProperties
(
prefix
=
"spring.data.elasticsearch"
)
public
class
ElasticsearchProperties
{
private
String
clusterName
=
"elasticsearch"
;
private
String
clusterNodes
;
private
boolean
local
=
true
;
public
String
getClusterName
()
{
return
this
.
clusterName
;
}
public
void
setClusterName
(
String
clusterName
)
{
this
.
clusterName
=
clusterName
;
}
public
String
getClusterNodes
()
{
return
this
.
clusterNodes
;
}
public
void
setClusterNodes
(
String
clusterNodes
)
{
this
.
clusterNodes
=
clusterNodes
;
}
public
Client
createClient
()
{
try
{
return
(
StringUtils
.
hasLength
(
this
.
clusterNodes
)
?
createTransportClient
()
:
createNodeClient
());
}
catch
(
Exception
ex
)
{
throw
new
IllegalStateException
(
ex
);
}
}
private
Client
createNodeClient
()
throws
Exception
{
NodeClientFactoryBean
factory
=
new
NodeClientFactoryBean
(
this
.
local
);
factory
.
setClusterName
(
this
.
clusterName
);
factory
.
afterPropertiesSet
();
return
factory
.
getObject
();
}
private
Client
createTransportClient
()
throws
Exception
{
TransportClientFactoryBean
factory
=
new
TransportClientFactoryBean
();
factory
.
setClusterName
(
this
.
clusterName
);
factory
.
setClusterNodes
(
this
.
clusterNodes
);
factory
.
afterPropertiesSet
();
return
factory
.
getObject
();
}
}
spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
99940337
...
...
@@ -9,6 +9,7 @@ org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration,\
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
org.springframework.boot.autoconfigure.data.ElasticsearchRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.JpaRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.MongoRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.SolrRepositoriesAutoConfiguration,\
...
...
@@ -22,6 +23,8 @@ org.springframework.boot.autoconfigure.jms.ActiveMQAutoConfiguration,\
org.springframework.boot.autoconfigure.jms.HornetQAutoConfiguration,\
org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration,\
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\
org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration,\
org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration,\
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
...
...
spring-boot-dependencies/pom.xml
View file @
99940337
...
...
@@ -182,6 +182,11 @@
<artifactId>
spring-boot-starter-batch
</artifactId>
<version>
1.1.0.BUILD-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-elasticsearch
</artifactId>
<version>
1.1.0.BUILD-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-gemfire
</artifactId>
...
...
spring-boot-samples/pom.xml
View file @
99940337
...
...
@@ -27,6 +27,7 @@
<module>
spring-boot-sample-amqp
</module>
<module>
spring-boot-sample-aop
</module>
<module>
spring-boot-sample-batch
</module>
<module>
spring-boot-sample-data-elasticsearch
</module>
<module>
spring-boot-sample-data-gemfire
</module>
<module>
spring-boot-sample-data-jpa
</module>
<module>
spring-boot-sample-data-mongodb
</module>
...
...
spring-boot-samples/spring-boot-sample-data-elasticsearch/.gitignore
0 → 100644
View file @
99940337
data
spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml
0 → 100644
View file @
99940337
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-samples
</artifactId>
<version>
1.1.0.BUILD-SNAPSHOT
</version>
</parent>
<artifactId>
spring-boot-sample-data-gemfire
</artifactId>
<packaging>
jar
</packaging>
<properties>
<main.basedir>
${basedir}/../..
</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-elasticsearch
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java
0 → 100644
View file @
99940337
/*
* Copyright 2012-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
data
.
elasticsearch
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.elasticsearch.annotations.Document
;
@Document
(
indexName
=
"customer"
,
type
=
"customer"
,
shards
=
1
,
replicas
=
0
,
refreshInterval
=
"-1"
)
public
class
Customer
{
@Id
private
String
id
;
private
String
firstName
;
private
String
lastName
;
public
Customer
()
{
}
public
Customer
(
String
firstName
,
String
lastName
)
{
this
.
firstName
=
firstName
;
this
.
lastName
=
lastName
;
}
public
String
getId
()
{
return
this
.
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getFirstName
()
{
return
this
.
firstName
;
}
public
void
setFirstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
}
public
String
getLastName
()
{
return
this
.
lastName
;
}
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"Customer[id=%s, firstName='%s', lastName='%s']"
,
this
.
id
,
this
.
firstName
,
this
.
lastName
);
}
}
spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/CustomerRepository.java
0 → 100644
View file @
99940337
/*
* Copyright 2012-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
data
.
elasticsearch
;
import
java.util.List
;
import
org.springframework.data.elasticsearch.repository.ElasticsearchRepository
;
public
interface
CustomerRepository
extends
ElasticsearchRepository
<
Customer
,
String
>
{
public
Customer
findByFirstName
(
String
firstName
);
public
List
<
Customer
>
findByLastName
(
String
lastName
);
}
spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/SampleElasticsearchApplication.java
0 → 100644
View file @
99940337
/*
* Copyright 2012-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
data
.
elasticsearch
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
@EnableAutoConfiguration
@ComponentScan
public
class
SampleElasticsearchApplication
implements
CommandLineRunner
{
@Autowired
private
CustomerRepository
repository
;
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
this
.
repository
.
deleteAll
();
saveCustomers
();
fetchAllCustomers
();
fetchIndividualCustomers
();
}
private
void
saveCustomers
()
{
this
.
repository
.
save
(
new
Customer
(
"Alice"
,
"Smith"
));
this
.
repository
.
save
(
new
Customer
(
"Bob"
,
"Smith"
));
}
private
void
fetchAllCustomers
()
{
System
.
out
.
println
(
"Customers found with findAll():"
);
System
.
out
.
println
(
"-------------------------------"
);
for
(
Customer
customer
:
this
.
repository
.
findAll
())
{
System
.
out
.
println
(
customer
);
}
System
.
out
.
println
();
}
private
void
fetchIndividualCustomers
()
{
System
.
out
.
println
(
"Customer found with findByFirstName('Alice'):"
);
System
.
out
.
println
(
"--------------------------------"
);
System
.
out
.
println
(
this
.
repository
.
findByFirstName
(
"Alice"
));
System
.
out
.
println
(
"Customers found with findByLastName('Smith'):"
);
System
.
out
.
println
(
"--------------------------------"
);
for
(
Customer
customer
:
this
.
repository
.
findByLastName
(
"Smith"
))
{
System
.
out
.
println
(
customer
);
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
SampleElasticsearchApplication
.
class
,
"--debug"
);
}
}
spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java
0 → 100644
View file @
99940337
/*
* Copyright 2012-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
data
.
elasticsearch
;
import
static
org
.
junit
.
Assert
.*;
import
java.net.ConnectException
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.springframework.boot.test.OutputCapture
;
import
org.springframework.core.NestedCheckedException
;
/**
* Tests for {@link SampleElasticsearchApplication}.
*
* @author Artur Konczak
*/
public
class
SampleElasticsearchApplicationTests
{
@Rule
public
OutputCapture
outputCapture
=
new
OutputCapture
();
@Test
public
void
testDefaultSettings
()
throws
Exception
{
try
{
SampleElasticsearchApplication
.
main
(
new
String
[
0
]);
}
catch
(
IllegalStateException
ex
)
{
if
(
serverNotRunning
(
ex
))
{
return
;
}
}
String
output
=
this
.
outputCapture
.
toString
();
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"firstName='Alice', lastName='Smith'"
));
}
private
boolean
serverNotRunning
(
IllegalStateException
ex
)
{
@SuppressWarnings
(
"serial"
)
NestedCheckedException
nested
=
new
NestedCheckedException
(
"failed"
,
ex
)
{
};
if
(
nested
.
contains
(
ConnectException
.
class
))
{
Throwable
root
=
nested
.
getRootCause
();
if
(
root
.
getMessage
().
contains
(
"Connection refused"
))
{
return
true
;
}
}
return
false
;
}
}
spring-boot-starters/pom.xml
View file @
99940337
...
...
@@ -24,6 +24,7 @@
<module>
spring-boot-starter-amqp
</module>
<module>
spring-boot-starter-aop
</module>
<module>
spring-boot-starter-batch
</module>
<module>
spring-boot-starter-data-elasticsearch
</module>
<module>
spring-boot-starter-data-gemfire
</module>
<module>
spring-boot-starter-data-jpa
</module>
<module>
spring-boot-starter-data-mongodb
</module>
...
...
spring-boot-starters/spring-boot-starter-data-elasticsearch/pom.xml
0 → 100644
View file @
99940337
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starters
</artifactId>
<version>
1.1.0.BUILD-SNAPSHOT
</version>
</parent>
<artifactId>
spring-boot-starter-data-elasticsearch
</artifactId>
<packaging>
jar
</packaging>
<properties>
<main.basedir>
${basedir}/../..
</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-elasticsearch
</artifactId>
</dependency>
</dependencies>
</project>
spring-boot-starters/spring-boot-starter-data-elasticsearch/src/main/resources/META-INF/spring.provides
0 → 100644
View file @
99940337
provides: spring-data-elasticsearch
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