Turn on and off the Spring Data Elasticsearch for SpringBoot application

79 Views Asked by At
  • What I am trying to achieve:

Turn on and off the Spring Data Elasticsearch for a SpringBoot application.

  • What did I try:

I am using this code:

@Configuration
public class MyElasticConfiguration extends ReactiveElasticsearchConfiguration {

    @Override
    public ClientConfiguration clientConfiguration() {
        return ClientConfiguration.builder().connectedTo("some-endpoint:9200").build();
    }

}

and this dependency:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.2.1</version>
    <relativePath/>
</parent>

    ...

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-elasticsearch</artifactId>
</dependency>

  • Actual result:

With the above, my SpringBoot application will try to connect to Elasticsearch on startup.

  • Expected result:

I wish to disable such connection attempts on startup.

  • Question:

I tried searching for a property like: spring.data.elasticsearch.enabled=false, but no luck finding something similar.

Is there a way to turn on/off spring data elasticsearch, via some kind of properties, or some kind of of annotation?

1

There are 1 best solutions below

0
Oscar On

Disable Spring configuration in bootstrap application class should solve your issue:

@SpringBootApplication(exclude = { MyElasticConfiguration.class })
YourProjectApplication {/*...*/}

You can also use @Profile to set an profile or exclude profile on MyElasticConfiguration class.