New client config requires dependency on spring-web and spring-webflux
Following the configuration from https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch-migration-guide-4.3-4.4.new-clients and using dependency spring-boot-starter-data-elasticsearch does not work.
Error:
java.lang.NoClassDefFoundError: org/springframework/http/HttpHeaders
requires spring-web
Error java.lang.TypeNotPresentException: Type org.springframework.web.reactive.function.client.WebClient not present
requires 'spring-webflux`
At least webflux dependency should be optional, but currently, without it, the configuration is not valid.
Related: https://github.com/spring-projects/spring-data-elasticsearch/issues/2189
Sample repo: https://github.com/cdalexndr/spring-data-elasticsearch-2272
Running test shows error.
See build.gradle for my comments. Adding dependencies fixes the config.
This is nothing that was introduced with the new client.
Spring Data Elasticsearch has a dependency on spring-web in this configuration with the import of org.springframework.http.HttpHeaders; this is in the code since December 2018. To be honest, I never noticed that and nobody else has brought it up so far. The issue you refer to was closed as this problem did not reproduce.
In the current version during build of Spring Data Elasticsearch this dependency can be satisfied by the optional spring-webflux which pulls in spring-web. I suppose this has gone unnoticed for so long, as probably Spring Data Elasticsearch is mostly used from within REST services that use spring-web.
So currently you will need to provide spring-web as dependency, spring-webflux would not be necessary.
But I think we should introduce some Header class into Spring Data Elasticsearch that is not dependent on underlying libraries and map this in the client implementations to the needed classes.
spring-webflux would not be necessary.
Actually, wiith spring-web dependency added, the configuration still fails with error:
java.lang.TypeNotPresentException: Type org.springframework.web.reactive.function.client.WebClient not present
can you please put a sample project (on GitHub) or somewhere else that reproduces this?
@sothawo it's already in the top post
The org.springframework.data.elasticsearch.client.ClientConfigurationBuilder has an import to WebClient needed for this method:
public ClientConfiguration.TerminalClientConfigurationBuilder withWebClientConfigurer(Function<WebClient, WebClient> webClientConfigurer)
I have a project that uses spring-boot-starter-web I have no problems with this as long as I do not try to use the above mentioned method. In this project I have no dependencies on webflux and it works.
This seems to be a problem related to the testing. The application itself starts and works without the webflux dependency, but for the test it is needed. So I suppose you add "spring-framework:spring-webflux" as a test dependency to your project.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.