spring-cloud / spring-cloud/spring-cloud-commons
Using @RefreshScope on configuration with RestHighLevelClient leads to null restClient
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 751
- Forks
- 744
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
Describe the bug
With spring data elasticsearch, when we used @RefreshScope on the configuration, the restClient is null and thus we can't perform operation on the cluster. Without this, it work perfectly fine.
Spring version:
spring boot starter parent 2.3.5
spring cloud config : 2.2.4
spring boot data elasticsearch 4.0.5
Sample
@Configuration
@EnableElasticsearchRepositories
public class ElasticConfig {
@Bean
@RefreshScope
public ElasticProperties elasticProperties() {
return new ElasticProperties();
}
@Bean
@RefreshScope
public RestHighLevelClient client() {
ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(elasticProperties().getClusterNodes()).build();
return RestClients.create(clientConfiguration).rest();
}
@Bean
@RefreshScope
public ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchRestTemplate(client());
}
}
Thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the sample ElasticConfig and reproduce the null RestHighLevelClient using the listed Spring Boot, Spring Cloud Config, and Spring Data Elasticsearch versions. Trace how @RefreshScope affects the ElasticProperties, client, and ElasticsearchRestTemplate beans; done means cluster operations work with @RefreshScope enabled without a null client.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elasticsearch, java, spring
- Domain
- backend, cloud, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100