spring-projects / spring-data-elasticsearch

Provide support to increase developer productivity in Java when using Elasticsearch. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-elasticsearch/
Apache License 2.0
2.9k stars 1.33k forks source link

Questions about using Spring Data Jpa and Spring Data Elasticsearch console information #2940

Closed mitu2 closed 1 month ago

mitu2 commented 2 months ago

problem description

I didn't use @EnableReactiveElasticsearchRepositories, But it seems to scan my code and throw out some info messages.I wonder why it works, and it generates a message every time I add a JPA repository.

2024-07-13T19:43:33.338+08:00  INFO 4648 --- [spring-data-example] [  restartedMain] .RepositoryConfigurationExtensionSupport : Spring Data Reactive Elasticsearch - Could not safely identify store assignment for repository candidate interface org.example.springdataexample.repositories.jdbc.ItemRepository; If you want this repository to be a Reactive Elasticsearch repository, consider annotating your entities with one of these annotations: org.springframework.data.elasticsearch.annotations.Document (preferred), or consider extending one of the following types with your repository: org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository
2024-07-13T19:43:33.338+08:00  INFO 4648 --- [spring-data-example] [  restartedMain] .RepositoryConfigurationExtensionSupport : Spring Data Reactive Elasticsearch - Could not safely identify store assignment for repository candidate interface org.example.springdataexample.repositories.jdbc.PersonRepository; If you want this repository to be a Reactive Elasticsearch repository, consider annotating your entities with one of these annotations: org.springframework.data.elasticsearch.annotations.Document (preferred), or consider extending one of the following types with your repository: org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository

I found that ReactiveElasticsearchRepositoriesAutoConfiguration triggers at the same time as ElasticsearchRepositoriesAutoConfiguration, and now I can only exclude one startup class to avoid it scanning my code with another

- @SpringBootApplication
+ @SpringBootApplication(exclude = ReactiveElasticsearchRepositoriesAutoConfiguration.class)
public class SpringDataExampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringDataExampleApplication.class, args);
    }

}

Is there a better way to avoid this?

example code

I told you about my example code uploaded to

https://github.com/mitu2/spring-data-example

sothawo commented 2 months ago

more complete output.

2024-07-14T20:15:34.567+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2024-07-14T20:15:34.567+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-07-14T20:15:34.618+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 42 ms. Found 2 JPA repository interfaces.
2024-07-14T20:15:34.620+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2024-07-14T20:15:34.621+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Elasticsearch repositories in DEFAULT mode.
2024-07-14T20:15:34.629+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7 ms. Found 1 Elasticsearch repository interface.
2024-07-14T20:15:34.857+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2024-07-14T20:15:34.858+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive Elasticsearch repositories in DEFAULT mode.
2024-07-14T20:15:34.875+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .RepositoryConfigurationExtensionSupport : Spring Data Reactive Elasticsearch - Could not safely identify store assignment for repository candidate interface org.example.springdataexample.repositories.jdbc.ItemRepository; If you want this repository to be a Reactive Elasticsearch repository, consider annotating your entities with one of these annotations: org.springframework.data.elasticsearch.annotations.Document (preferred), or consider extending one of the following types with your repository: org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository
2024-07-14T20:15:34.876+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .RepositoryConfigurationExtensionSupport : Spring Data Reactive Elasticsearch - Could not safely identify store assignment for repository candidate interface org.example.springdataexample.repositories.jdbc.PersonRepository; If you want this repository to be a Reactive Elasticsearch repository, consider annotating your entities with one of these annotations: org.springframework.data.elasticsearch.annotations.Document (preferred), or consider extending one of the following types with your repository: org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository
2024-07-14T20:15:34.876+02:00  INFO 4171 --- [spring-data-example] [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 17 ms. Found 0 Reactive Elasticsearch repository interfaces.

@mp911de can you explain why reactive repositories are searched here?

phelan commented 1 month ago

you can set spring.data.elasticsearch.repositories.enabled=false in config to avoid spring data scan your repositories

sothawo commented 1 month ago

The question is not how to disable repository scanning, but why a reactive repository scan is done.

mp911de commented 1 month ago

Reactive repositories are enabled by Spring Boot via ReactiveElasticsearchRepositoriesAutoConfiguration when ReactiveElasticsearchClient and ReactiveElasticsearchRepository are on the classpath. Store arrangements where reactive components are part of the actual Spring Data module always provide these foundational types, however, the dependant bits such as Mono and Flux aren't on the classpath so ideally, these should be considered in Boot's ReactiveElasticsearchRepositoriesAutoConfiguration. I suggest reaching out to the Boot team for refining the condition setup.

mitu2 commented 1 month ago

I mirrored it. https://github.com/spring-projects/spring-boot/issues/41672