-
Notifications
You must be signed in to change notification settings - Fork 40.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ElasticsearchDataAutoConfiguration: the auto configuration is applied even when the classpath does not have the required classes #33010
Comments
Hello @reta, thanks for reaching out. If I understand correctly, this requires an application to depend on "spring-data-elasticsearch" but explicitly exclude a mandatory compile dependency listed in its POM (here the elasticsearch client). I'm not sure we can consider that a valid use case, otherwise the "spring-data-elasticsearch" project would have made it optional in the first place. I'm marking this for team-discussion so this is reviewed by the team. Doing so would have very broad implications as we would need to mark as conditional many auto-configurations for similar use cases and we would need to have integration tests for those. |
Helllo @bclozel, thank you for reply That is correct, we have discussed that specific implementation with the Spring / Spring Data Elasticsearch team (@mp911de and @sothawo). As you rightly mention, it may not be a valid case for Spring Data Elasticsearch but for integrations built on top of it (and to reassure, none of the Spring Data Elasticsearch integrations are going to be affected). Thank you. |
This autoconfiguration is applied when |
Absolutely, and we will, but the issue is that |
As it should because the client is a mandatory dependency of Spring Data Elasticsearch. If Spring Data Elasticsearch is intended to be used without the Elastichsearch client, it should become an optional dependency. Until that time, for the reasons that Brian has explained above, we may not want to change Spring Boot. |
To add a bit more details may be, the non-reactive (JavaClientConfiguration) has the
I could also think of a valid Spring Data Elasticsearch scenario when the user wants to use |
The Spring Data Elasticsearch 4.4 had the |
For 5.0.0, both clients are supported (even deprecated one before it gets removed in 5.1), we should not require both clients on the classpath if the user took a risk to use |
The user can still use the old
Making the new client optional in Spring Data Elasticsearch and relying on the user to include the dependency in the right version would be an accident waiting to happen. Elasticsearch often enough has API changes even in patch level updates. |
@sothawo sure, I agree with what you said and the path forward makes sense to me. There is no even a suggestion to change the dependencies in any form, even more - no changes at all for Spring Data Elasticsearch. The only compelling case I am trying to make (beside "selfish" goal to better support OpenSearch) - I thought it makes sense to provide the way for user to flip the dependencies at own will and Spring Boot should not complain (it totally makes sense to me). @bclozel @wilkinsona thank you for you time, closing the issue since there is no interest in the addressing such option. |
Problem
This is a joint discovery with @sothawo (see please [1] for the context).
Together we have built the Spring Data integration for OpenSearch [2] which is based on the upcoming Spring Data Elasticsearch 5.0.0 (in RC2 now). The OpenSearch integration relies on the client abstraction provided by Spring Data Elasticsearch (since OpenSearch and Elasticseach at least at this moment have very similar REST based clients) but excludes every single Elasticsearch dependency. It works fine in most cases but when used with Spring Boot 3.0.0 (in RC1 now), there is an exception at startup:
The reason for it is that
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataConfiguration$ReactiveRestClientConfiguration
is being instantiated and inspected even when the classpath does not have the required classes (in this caseReactiveElasticsearchClient
needsElasticsearchTransport
). The fix seems to be simple and low risk:@ConditionalOnClass(ElasticsearchTransport.class)
(technically, we could useApiClient
but they both come in the same bundle).Hope it makes sense.
Thank you.
[1] opensearch-project/spring-data-opensearch#1 (comment)
[2] https://github.com/opensearch-project/spring-data-opensearch
The text was updated successfully, but these errors were encountered: