Fix Elasticsearch template condition if no client is defined
This commit makes sure to backoff if a Client bean is not available. Closes gh-10143
This commit is contained in:
		
							parent
							
								
									5fc01880bc
								
							
						
					
					
						commit
						db18abc542
					
				| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2012-2015 the original author or authors.
 | 
			
		||||
 * Copyright 2012-2017 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.
 | 
			
		||||
| 
						 | 
				
			
			@ -20,6 +20,7 @@ import org.elasticsearch.client.Client;
 | 
			
		|||
 | 
			
		||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
 | 
			
		||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
| 
						 | 
				
			
			@ -49,6 +50,7 @@ public class ElasticsearchDataAutoConfiguration {
 | 
			
		|||
 | 
			
		||||
	@Bean
 | 
			
		||||
	@ConditionalOnMissingBean
 | 
			
		||||
	@ConditionalOnBean(Client.class)
 | 
			
		||||
	public ElasticsearchTemplate elasticsearchTemplate(Client client,
 | 
			
		||||
			ElasticsearchConverter converter) {
 | 
			
		||||
		try {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,6 +46,14 @@ public class ElasticsearchDataAutoConfigurationTests {
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	public void templateBackOffWithNoClient() {
 | 
			
		||||
		this.context = new AnnotationConfigApplicationContext(
 | 
			
		||||
				ElasticsearchDataAutoConfiguration.class);
 | 
			
		||||
		assertThat(this.context.getBeanNamesForType(ElasticsearchTemplate.class))
 | 
			
		||||
				.isEmpty();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	public void templateExists() {
 | 
			
		||||
		load("spring.data.elasticsearch.properties.path.data:target/data",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue