Springboot 2.3.0以后版本不支持自动注入JestClient,如下图我们在yml文件中配置JestClient时会出现划掉的线提示。我们采取手动配置的方式。如果只修改springboot版本,不手动添加bean注入会出现以下报错:
java Parameter 0 of constructor in xx.xx.xx.SearchServiceImpl required a bean of type 'io.searchbox.client.JestClient' that could not be found. 采用手动注入的方式:
@Test
void contextLoads() {
JestClient jestClient = getJestCline();
//List<PmsSkuInfo> pmsSkuInfos= skuService.findAllSkuInfo();
System.out.println("jestClient"+jestClient);
}
public JestClient getJestCline(){
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
.Builder("http://10.12.11.100:9200")
.multiThreaded(true)
.build());
return factory.getObject();
` 这样就不会报错了。