[英]Turn off embedded Elasticsearch in Spring Boot test
默認情況下,Spring Boot將創建一個嵌入式Elasticsearch。 可以通過設置spring.data.elasticsearch.cluster-nodes將其關閉。 但是,我不確定如何在JUnit測試中執行此操作。 例如,我有:
@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());
}
}
如果我設置了適當的環境變量(例如spring.data.elasticsearch.cluster-node = host:9300),它將連接到遠程Elasticsearch。 我可以以某種方式直接在此測試上設置此值嗎?
只需在禁用了spring.data.elasticsearch.cluster-nodes
src/test/resources
創建第二個application.properties
文件。 Spring Boot將使用該文件代替src/main/resources
PROD配置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.