Reputation: 41
By default, Spring Boot will create an embedded Elasticsearch. It can be turned off by setting spring.data.elasticsearch.cluster-nodes. However, I'm not sure how to do this in a JUnit test. For example, I have:
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(RemoteElasticsearch.class)
@SpringBootApplication(
scanBasePackageClasses = {
}
)
@EnableElasticsearchRepositories(basePackages = "com.example.me.repo")
public class RemoteElasticsearch {
@Inject
private SomeRepo someRepo;
@Test
public void test(){
someRepo.save(new Something());
}
}
It connects to the remote elasticsearch if I set the appropriate environment variable (eg spring.data.elasticsearch.cluster-node=host:9300). Can I somehow set this value directly on this test?
Upvotes: 2
Views: 2781
Reputation: 24561
Just create second application.properties
file in src/test/resources
with spring.data.elasticsearch.cluster-nodes
disabled. Spring Boot will use this file instead PROD configuration from src/main/resources
.
Upvotes: 1