Auto-configured Data Elasticsearch Tests
You can use @DataElasticsearchTest
to test Elasticsearch applications.
By default, it configures an ElasticsearchRestTemplate
, scans for @Document
classes, and configures Spring Data Elasticsearch repositories.
Regular @Component
and @ConfigurationProperties
beans are not scanned when the @DataElasticsearchTest
annotation is used.
@EnableConfigurationProperties
can be used to include @ConfigurationProperties
beans.
(For more about using Elasticsearch with Spring Boot, see "Elasticsearch", earlier in this chapter.)
A list of the auto-configuration settings that are enabled by @DataElasticsearchTest can be found in the appendix.
|
The following example shows a typical setup for using Elasticsearch tests in Spring Boot:
-
Java
-
Kotlin
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest;
@DataElasticsearchTest
class MyDataElasticsearchTests {
@Autowired
private SomeRepository repository;
// ...
}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest
@DataElasticsearchTest
class MyDataElasticsearchTests(@Autowired val repository: SomeRepository) {
// ...
}