resttemplate和elasticsearch高级rest客户端

jk9hmnmh  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(0)|浏览(498)

在一个服务中,我在单独的文件中定义了2个配置,如下所示:

@Configuration
public class Config1 {

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
        return restTemplateBuilder.setConnectTimeout(1000000).setReadTimeout(1000000).build();
    }

}

@Configuration
public class ElasticsearchConfig {

    @Bean(destroyMethod="close")
    public RestHighLevelClient client() {

        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();

        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, pass));

        RestClientBuilder builder = RestClient.builder(new HttpHost(elasticsearchHost,9200,"http")).setHttpClientConfigCallback(
                    httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));

        return new RestHighLevelClient(builder);
    }

}

我在调用rest模板交换时看到了一些意想不到的行为,这两个bean的创建是否相互干扰?为什么?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题