spring-cloud / spring-cloud/spring-cloud-commons

Using @RefreshScope on configuration with RestHighLevelClient leads to null restClient

Open
#852 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback-provided
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.