Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring引导Rest模板-CloseableHttpClient_Spring_Spring Boot_Spring Rest - Fatal编程技术网

Spring引导Rest模板-CloseableHttpClient

Spring引导Rest模板-CloseableHttpClient,spring,spring-boot,spring-rest,Spring,Spring Boot,Spring Rest,我正在Spring boot应用程序中定义CloseableHttpClient类型的bean。但是我仍然得到了一个错误,那就是找不到bean @Bean @Primary public RestTemplate restTemplate(RestTemplateBuilder builder, @Qualifier("pooledClient") CloseableHttpClient httpClient) { return builder.requestFactory(new Ht

我正在Spring boot应用程序中定义CloseableHttpClient类型的bean。但是我仍然得到了一个错误,那就是找不到bean

@Bean
@Primary
public RestTemplate restTemplate(RestTemplateBuilder builder, @Qualifier("pooledClient") CloseableHttpClient httpClient) {
    return builder.requestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)).build();
}

@Bean
public CloseableHttpClient httpClient() {
    return HttpClientBuilder.create().build();
}
com.MyConfiguration中方法restTemplate的参数1需要找不到类型为“org.apache.http.impl.client.CloseableHttpClient”的bean

@Bean
@Primary
public RestTemplate restTemplate(RestTemplateBuilder builder, @Qualifier("pooledClient") CloseableHttpClient httpClient) {
    return builder.requestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)).build();
}

@Bean
public CloseableHttpClient httpClient() {
    return HttpClientBuilder.create().build();
}
行动:


考虑在您的配置中定义“org.apache.http.impl.client.CloseableHttpClient”类型的bean。

您正在为CloseableHttpClient使用
@限定符
,但在您的配置中,您没有定义任何与该限定符匹配的bean。您可以声明一个名为pooledClient的bean:

@Bean(name="pooledClient")
public CloseableHttpClient httpClient() {
    return HttpClientBuilder.create().build();
}
或者删除@Qualifier注释:

@Bean
@Primary
public RestTemplate restTemplate(RestTemplateBuilder builder, CloseableHttpClient httpClient) {
    return builder.requestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)).build();
}

您正在为CloseableHttpClient使用一个
@限定符
,但在您的配置中没有定义任何与该限定符匹配的bean。您可以声明一个名为pooledClient的bean:

@Bean(name="pooledClient")
public CloseableHttpClient httpClient() {
    return HttpClientBuilder.create().build();
}
或者删除@Qualifier注释:

@Bean
@Primary
public RestTemplate restTemplate(RestTemplateBuilder builder, CloseableHttpClient httpClient) {
    return builder.requestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)).build();
}