From 99940337a9445e16beed92becd2a21656f55bac4 Mon Sep 17 00:00:00 2001 From: Artur Konczak Date: Sun, 1 Jun 2014 12:32:46 +0100 Subject: [PATCH 1/3] Add support for Elasticsearch Add auto-configuration and starters for Elasticsearch. Fixes gh-408 --- spring-boot-autoconfigure/pom.xml | 5 ++ ...icsearchRepositoriesAutoConfiguration.java | 44 ++++++++++ ...rchRepositoriesAutoConfigureRegistrar.java | 57 +++++++++++++ .../ElasticsearchAutoConfiguration.java | 74 +++++++++++++++++ .../ElasticsearchDataAutoConfiguration.java | 52 ++++++++++++ .../ElasticsearchProperties.java | 82 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 3 + spring-boot-dependencies/pom.xml | 5 ++ spring-boot-samples/pom.xml | 1 + .../.gitignore | 1 + .../pom.xml | 39 +++++++++ .../sample/data/elasticsearch/Customer.java | 70 ++++++++++++++++ .../elasticsearch/CustomerRepository.java | 29 +++++++ .../SampleElasticsearchApplication.java | 71 ++++++++++++++++ .../SampleElasticsearchApplicationTests.java | 66 +++++++++++++++ spring-boot-starters/pom.xml | 1 + .../pom.xml | 26 ++++++ .../main/resources/META-INF/spring.provides | 1 + 18 files changed, 627 insertions(+) create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfiguration.java create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfigureRegistrar.java create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchDataAutoConfiguration.java create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java create mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/.gitignore create mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml create mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java create mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/CustomerRepository.java create mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/SampleElasticsearchApplication.java create mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java create mode 100644 spring-boot-starters/spring-boot-starter-data-elasticsearch/pom.xml create mode 100644 spring-boot-starters/spring-boot-starter-data-elasticsearch/src/main/resources/META-INF/spring.provides diff --git a/spring-boot-autoconfigure/pom.xml b/spring-boot-autoconfigure/pom.xml index 017a68059f..b7fc565c62 100644 --- a/spring-boot-autoconfigure/pom.xml +++ b/spring-boot-autoconfigure/pom.xml @@ -186,6 +186,11 @@ spring-data-redis true + + org.springframework.data + spring-data-elasticsearch + true + org.springframework.data spring-data-solr diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfiguration.java new file mode 100644 index 0000000000..aedab9c4c7 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfiguration.java @@ -0,0 +1,44 @@ +/* + * 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 { + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfigureRegistrar.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfigureRegistrar.java new file mode 100644 index 0000000000..6e9bf01732 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfigureRegistrar.java @@ -0,0 +1,57 @@ +/* + * 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 getAnnotation() { + return EnableElasticsearchRepositories.class; + } + + @Override + protected Class getConfiguration() { + return EnableElasticsearchRepositoriesConfiguration.class; + } + + @Override + protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() { + return new ElasticsearchRepositoryConfigExtension(); + } + + @EnableElasticsearchRepositories + private static class EnableElasticsearchRepositoriesConfiguration { + + } + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java new file mode 100644 index 0000000000..1a3dfe6948 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java @@ -0,0 +1,74 @@ +/* + * 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); + } + } + } + } + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchDataAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchDataAutoConfiguration.java new file mode 100644 index 0000000000..e82d84cd3f --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchDataAutoConfiguration.java @@ -0,0 +1,52 @@ +/* + * 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. + *

+ * 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); + } + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java new file mode 100644 index 0000000000..bea364afcd --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java @@ -0,0 +1,82 @@ +/* + * 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(); + } + +} diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 1696504f29..1b87fe1957 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -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,\ diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index b4f776cbea..b1cf30eee3 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -182,6 +182,11 @@ spring-boot-starter-batch 1.1.0.BUILD-SNAPSHOT + + org.springframework.boot + spring-boot-starter-data-elasticsearch + 1.1.0.BUILD-SNAPSHOT + org.springframework.boot spring-boot-starter-data-gemfire diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index 881c2e013d..18e2cc5135 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -27,6 +27,7 @@ spring-boot-sample-amqp spring-boot-sample-aop spring-boot-sample-batch + spring-boot-sample-data-elasticsearch spring-boot-sample-data-gemfire spring-boot-sample-data-jpa spring-boot-sample-data-mongodb diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/.gitignore b/spring-boot-samples/spring-boot-sample-data-elasticsearch/.gitignore new file mode 100644 index 0000000000..1269488f7f --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/.gitignore @@ -0,0 +1 @@ +data diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml b/spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml new file mode 100644 index 0000000000..d4e76673cb --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 1.1.0.BUILD-SNAPSHOT + + spring-boot-sample-data-gemfire + jar + + ${basedir}/../.. + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-data-elasticsearch + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java new file mode 100644 index 0000000000..2bfb6b81a5 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java @@ -0,0 +1,70 @@ +/* + * 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); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/CustomerRepository.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/CustomerRepository.java new file mode 100644 index 0000000000..295768e7ec --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/CustomerRepository.java @@ -0,0 +1,29 @@ +/* + * 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 { + + public Customer findByFirstName(String firstName); + + public List findByLastName(String lastName); + +} diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/SampleElasticsearchApplication.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/SampleElasticsearchApplication.java new file mode 100644 index 0000000000..6cae86904f --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/SampleElasticsearchApplication.java @@ -0,0 +1,71 @@ +/* + * 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"); + } +} diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java new file mode 100644 index 0000000000..eb91dc4929 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java @@ -0,0 +1,66 @@ +/* + * 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; + } + +} diff --git a/spring-boot-starters/pom.xml b/spring-boot-starters/pom.xml index 6d128af05c..1b65ebd2ce 100644 --- a/spring-boot-starters/pom.xml +++ b/spring-boot-starters/pom.xml @@ -24,6 +24,7 @@ spring-boot-starter-amqp spring-boot-starter-aop spring-boot-starter-batch + spring-boot-starter-data-elasticsearch spring-boot-starter-data-gemfire spring-boot-starter-data-jpa spring-boot-starter-data-mongodb diff --git a/spring-boot-starters/spring-boot-starter-data-elasticsearch/pom.xml b/spring-boot-starters/spring-boot-starter-data-elasticsearch/pom.xml new file mode 100644 index 0000000000..c850a0c07c --- /dev/null +++ b/spring-boot-starters/spring-boot-starter-data-elasticsearch/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starters + 1.1.0.BUILD-SNAPSHOT + + spring-boot-starter-data-elasticsearch + jar + + ${basedir}/../.. + + + + ${project.groupId} + spring-boot-starter + ${project.version} + + + org.springframework.data + spring-data-elasticsearch + + + diff --git a/spring-boot-starters/spring-boot-starter-data-elasticsearch/src/main/resources/META-INF/spring.provides b/spring-boot-starters/spring-boot-starter-data-elasticsearch/src/main/resources/META-INF/spring.provides new file mode 100644 index 0000000000..5ab75ebfda --- /dev/null +++ b/spring-boot-starters/spring-boot-starter-data-elasticsearch/src/main/resources/META-INF/spring.provides @@ -0,0 +1 @@ +provides: spring-data-elasticsearch From c43fd04f3e06c2519fe7a65f281af74a34eddfbb Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 1 Jun 2014 12:33:56 +0100 Subject: [PATCH 2/3] Add Elasticsearch tests Add unit tests for elasticsearch packages. Also refactor some of the existing tests to prevent Repository clashes. See gh-408 --- spring-boot-autoconfigure/.gitignore | 1 + ...JpaRepositoriesAutoConfigurationTests.java | 14 +++- .../data/JpaWebAutoConfigurationTests.java | 9 +++ ...ngoRepositoriesAutoConfigurationTests.java | 11 ++- ...olrRepositoriesAutoConfigurationTests.java | 11 ++- .../data/alt/CityJpaRepository.java | 24 ------ .../data/alt/CityMongoDbRepository.java | 24 ------ .../data/alt/CitySolrRepository.java | 24 ------ .../ElasticsearchAutoConfigurationTests.java | 76 +++++++++++++++++++ ...asticsearchDataAutoConfigurationTests.java | 52 +++++++++++++ 10 files changed, 166 insertions(+), 80 deletions(-) create mode 100644 spring-boot-autoconfigure/.gitignore delete mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityJpaRepository.java delete mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityMongoDbRepository.java delete mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CitySolrRepository.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfigurationTests.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchDataAutoConfigurationTests.java diff --git a/spring-boot-autoconfigure/.gitignore b/spring-boot-autoconfigure/.gitignore new file mode 100644 index 0000000000..1269488f7f --- /dev/null +++ b/spring-boot-autoconfigure/.gitignore @@ -0,0 +1 @@ +data diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java index e5222c32fd..ead72fe74b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java @@ -18,11 +18,12 @@ package org.springframework.boot.autoconfigure.data; import javax.persistence.EntityManagerFactory; +import org.junit.After; import org.junit.Test; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; -import org.springframework.boot.autoconfigure.data.alt.CityMongoDbRepository; -import org.springframework.boot.autoconfigure.data.alt.CitySolrRepository; +import org.springframework.boot.autoconfigure.data.alt.mongo.CityMongoDbRepository; +import org.springframework.boot.autoconfigure.data.alt.solr.CitySolrRepository; import org.springframework.boot.autoconfigure.data.jpa.City; import org.springframework.boot.autoconfigure.data.jpa.CityRepository; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; @@ -46,6 +47,11 @@ public class JpaRepositoriesAutoConfigurationTests { private AnnotationConfigApplicationContext context; + @After + public void close() { + this.context.close(); + } + @Test public void testDefaultRepositoryConfiguration() throws Exception { this.context = new AnnotationConfigApplicationContext(); @@ -70,7 +76,7 @@ public class JpaRepositoriesAutoConfigurationTests { PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertNotNull(this.context - .getBean(org.springframework.boot.autoconfigure.data.alt.CityJpaRepository.class)); + .getBean(org.springframework.boot.autoconfigure.data.alt.jpa.CityJpaRepository.class)); assertNotNull(this.context.getBean(PlatformTransactionManager.class)); assertNotNull(this.context.getBean(EntityManagerFactory.class)); } @@ -82,7 +88,7 @@ public class JpaRepositoriesAutoConfigurationTests { } @Configuration - @EnableJpaRepositories(basePackageClasses = org.springframework.boot.autoconfigure.data.alt.CityJpaRepository.class, excludeFilters = { + @EnableJpaRepositories(basePackageClasses = org.springframework.boot.autoconfigure.data.alt.jpa.CityJpaRepository.class, excludeFilters = { @Filter(type = FilterType.ASSIGNABLE_TYPE, value = CityMongoDbRepository.class), @Filter(type = FilterType.ASSIGNABLE_TYPE, value = CitySolrRepository.class) }) @TestAutoConfigurationPackage(City.class) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaWebAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaWebAutoConfigurationTests.java index 75a6843fc9..6f7bae66cf 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaWebAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaWebAutoConfigurationTests.java @@ -16,9 +16,11 @@ package org.springframework.boot.autoconfigure.data; +import org.junit.After; import org.junit.Test; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.data.JpaRepositoriesAutoConfiguration.JpaWebConfiguration; import org.springframework.boot.autoconfigure.data.jpa.City; import org.springframework.boot.autoconfigure.data.jpa.CityRepository; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; @@ -34,12 +36,19 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; /** + * Tests for {@link JpaWebConfiguration}. + * * @author Dave Syer */ public class JpaWebAutoConfigurationTests { private AnnotationConfigWebApplicationContext context; + @After + public void close() { + this.context.close(); + } + @Test public void testDefaultRepositoryConfiguration() throws Exception { this.context = new AnnotationConfigWebApplicationContext(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/MongoRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/MongoRepositoriesAutoConfigurationTests.java index 4914052ef7..c51c2f86d0 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/MongoRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/MongoRepositoriesAutoConfigurationTests.java @@ -16,10 +16,12 @@ package org.springframework.boot.autoconfigure.data; +import org.junit.After; import org.junit.Test; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; -import org.springframework.boot.autoconfigure.data.alt.CityMongoDbRepository; +import org.springframework.boot.autoconfigure.data.alt.mongo.CityMongoDbRepository; +import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.autoconfigure.data.mongo.City; import org.springframework.boot.autoconfigure.data.mongo.CityRepository; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; @@ -46,6 +48,11 @@ public class MongoRepositoriesAutoConfigurationTests { private AnnotationConfigApplicationContext context; + @After + public void close() { + this.context.close(); + } + @Test public void testDefaultRepositoryConfiguration() throws Exception { this.context = new AnnotationConfigApplicationContext(); @@ -91,7 +98,7 @@ public class MongoRepositoriesAutoConfigurationTests { } @Configuration - @TestAutoConfigurationPackage(MongoRepositoriesAutoConfigurationTests.class) + @TestAutoConfigurationPackage(EmptyDataPackage.class) protected static class EmptyConfiguration { } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigurationTests.java index f3c6ed154e..ed31665d1f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/SolrRepositoriesAutoConfigurationTests.java @@ -18,10 +18,12 @@ package org.springframework.boot.autoconfigure.data; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.impl.HttpSolrServer; +import org.junit.After; import org.junit.Test; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; -import org.springframework.boot.autoconfigure.data.alt.CitySolrRepository; +import org.springframework.boot.autoconfigure.data.alt.solr.CitySolrRepository; +import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.autoconfigure.data.solr.City; import org.springframework.boot.autoconfigure.data.solr.CityRepository; import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration; @@ -42,6 +44,11 @@ public class SolrRepositoriesAutoConfigurationTests { private AnnotationConfigApplicationContext context; + @After + public void close() { + this.context.close(); + } + @Test public void testDefaultRepositoryConfiguration() { initContext(TestConfiguration.class); @@ -80,7 +87,7 @@ public class SolrRepositoriesAutoConfigurationTests { } @Configuration - @TestAutoConfigurationPackage(SolrRepositoriesAutoConfigurationTests.class) + @TestAutoConfigurationPackage(EmptyDataPackage.class) static class EmptyConfiguration { } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityJpaRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityJpaRepository.java deleted file mode 100644 index 1918fa6a4c..0000000000 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityJpaRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.alt; - -import org.springframework.boot.autoconfigure.data.jpa.City; -import org.springframework.data.repository.Repository; - -public interface CityJpaRepository extends Repository { - -} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityMongoDbRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityMongoDbRepository.java deleted file mode 100644 index e4547f1232..0000000000 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityMongoDbRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.alt; - -import org.springframework.boot.autoconfigure.data.mongo.City; -import org.springframework.data.repository.Repository; - -public interface CityMongoDbRepository extends Repository { - -} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CitySolrRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CitySolrRepository.java deleted file mode 100644 index 6a95279d43..0000000000 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CitySolrRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.alt; - -import org.springframework.boot.autoconfigure.data.solr.City; -import org.springframework.data.repository.Repository; - -public interface CitySolrRepository extends Repository { - -} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfigurationTests.java new file mode 100644 index 0000000000..caaa0e20e5 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfigurationTests.java @@ -0,0 +1,76 @@ +/* + * 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.elasticsearch.client.node.NodeClient; +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.hamcrest.Matchers.instanceOf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +/** + * Tests for {@link ElasticsearchAutoConfiguration}. + * + * @author Phillip Webb + */ +public class ElasticsearchAutoConfigurationTests { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private AnnotationConfigApplicationContext context; + + @After + public void close() { + if (this.context != null) { + this.context.close(); + } + } + + @Test + public void createNodeClient() { + this.context = new AnnotationConfigApplicationContext( + PropertyPlaceholderAutoConfiguration.class, + ElasticsearchAutoConfiguration.class); + assertEquals(1, this.context.getBeanNamesForType(Client.class).length); + assertThat(this.context.getBean(Client.class), instanceOf(NodeClient.class)); + } + + @Test + public void createTransportClient() throws Exception { + // We don't have a local elasticsearch server so use an address that's missing + // a port and check the exception + this.context = new AnnotationConfigApplicationContext(); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.data.elasticsearch.cluster-nodes:localhost"); + this.context.register(PropertyPlaceholderAutoConfiguration.class, + ElasticsearchAutoConfiguration.class); + this.thrown.expect(BeanCreationException.class); + this.thrown.expectMessage("port"); + this.context.refresh(); + } + +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchDataAutoConfigurationTests.java new file mode 100644 index 0000000000..d7f807db93 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchDataAutoConfigurationTests.java @@ -0,0 +1,52 @@ +/* + * 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.junit.After; +import org.junit.Test; +import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for {@link ElasticsearchDataAutoConfiguration}. + * + * @author Phillip Webb + */ +public class ElasticsearchDataAutoConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @After + public void close() { + if (this.context != null) { + this.context.close(); + } + } + + @Test + public void templateExists() { + this.context = new AnnotationConfigApplicationContext( + PropertyPlaceholderAutoConfiguration.class, + ElasticsearchAutoConfiguration.class, + ElasticsearchDataAutoConfiguration.class); + assertEquals(1, + this.context.getBeanNamesForType(ElasticsearchTemplate.class).length); + } +} From 0e4b1a4ad0880d1add255348dc490a54393ffbae Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 1 Jun 2014 12:49:26 +0100 Subject: [PATCH 3/3] Add Elasticsearch appendix links See gh-408 --- .../src/main/asciidoc/appendix-application-properties.adoc | 5 +++++ .../main/asciidoc/appendix-auto-configuration-classes.adoc | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 3c44b9f7f8..37d748fc54 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -196,6 +196,11 @@ content into your application; rather pick only the properties that you need. spring.data.solr.host=http://127.0.0.1:8983/solr spring.data.solr.zkHost= + # ELASTICSEARCH ({sc-spring-boot-autoconfigure}/elasticsearch/ElasticsearchProperties.{sc-ext}[ElasticsearchProperties}]) + spring.data.elasticsearch.cluster-name= # The cluster name (defaults to elasticsearch) + spring.data.elasticsearch.cluster-node= # The address of the server node (if not specified starts a client node) + spring.data.elasticsearch.local=true # if local mode should be used with client nodes + # FLYWAY ({sc-spring-boot-autoconfigure}/flyway/FlywayProperties.{sc-ext}[FlywayProperties]) flyway.locations=classpath:db/migrations # locations of migrations scripts flyway.schemas= # schemas to update diff --git a/spring-boot-docs/src/main/asciidoc/appendix-auto-configuration-classes.adoc b/spring-boot-docs/src/main/asciidoc/appendix-auto-configuration-classes.adoc index 6fb5bffbe5..f61ff96c50 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-auto-configuration-classes.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-auto-configuration-classes.adoc @@ -35,9 +35,15 @@ The following auto-configuration classes are from the `spring-boot-autoconfigure |{sc-spring-boot-autoconfigure}/web/DispatcherServletAutoConfiguration.{sc-ext}[DispatcherServletAutoConfiguration] |{dc-spring-boot-autoconfigure}/web/DispatcherServletAutoConfiguration.{dc-ext}[javadoc] +|{sc-spring-boot-autoconfigure}/elasticsearch/ElasticsearchAutoConfiguration.{sc-ext}[ElasticsearchAutoConfiguration] +|{dc-spring-boot-autoconfigure}/elasticsearch/ElasticsearchAutoConfiguration.{dc-ext}[javadoc] + |{sc-spring-boot-autoconfigure}/web/EmbeddedServletContainerAutoConfiguration.{sc-ext}[EmbeddedServletContainerAutoConfiguration] |{dc-spring-boot-autoconfigure}/web/EmbeddedServletContainerAutoConfiguration.{dc-ext}[javadoc] +|{sc-spring-boot-autoconfigure}/data/ElasticsearchRepositoriesAutoConfiguration.{sc-ext}[ElasticsearchRepositoriesAutoConfiguration] +|{dc-spring-boot-autoconfigure}/data/ElasticsearchRepositoriesAutoConfiguration.{dc-ext}[javadoc] + |{sc-spring-boot-autoconfigure}/social/FacebookAutoConfiguration.{sc-ext}[FacebookAutoConfiguration] |{dc-spring-boot-autoconfigure}/social/FacebookAutoConfiguration.{dc-ext}[javadoc]