Spring Boot 3.x.x не поддерживает httpclient4JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Spring Boot 3.x.x не поддерживает httpclient4

Сообщение Anonymous »

Я столкнулся с некоторой ошибкой при реализации конфигурации клиента Apache Http для моего RestTemplate.
Я использую версию SpringBoot 3.4.1 и обнаружил, что она по умолчанию поддерживает httpclient5
Я пытаюсь настроить свой RestTemplate.
Ниже приведен класс, который я настраиваю:

Код: Выделить всё

@Configuration
public class BlockingRestTemplateCustomizer  {

@Bean("restTemplate")
public RestTemplate restTemplate() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(100);
connectionManager.setDefaultMaxPerRoute(20);

RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(3000)
.build();

HttpClient httpClient = HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.build();

ClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);   // Line A  CTE Error
return new RestTemplate(factory);
}
}

Error I am facing error @ Line A compile time Error , it says that httpclient --> parameter should be of httpclient5 type
Но я хочу использовать зависимости httpclient4.
Я обновил свой pom, добавив зависимость ниже:

Код: Выделить всё

org.springframework.boot
spring-boot-starter-web


org.apache.httpcomponents
httpclient5




org.apache.httpcomponents
httpclient
4.5.13 


org.apache.httpcomponents
httpcore
4.4.14 

И в моем основном классе Java я исключаю конфигурацию Resttemplate по умолчанию для Spring Boot, как показано ниже:

Код: Выделить всё

@SpringBootApplication
@EnableAutoConfiguration(exclude = {
RestTemplateAutoConfiguration.class,
HttpClientAutoConfiguration.class
})// Exclude RestTemplate auto-configuration
public class MsscBreweryClientApplication {

public static void main(String[] args) {
SpringApplication.run(MsscBreweryClientApplication.class, args);
}

}
But Still error is prevailing , is there  a way to httpclient4 inclusion in springBoot 3.x.x version .
Примечание. Решение ChatGpt у меня тоже не работает. Я попробовал исключить httpclient5 из зависимости pom и добавил httpclient4. Но в коде, похоже, все еще ожидается httpclient5
Спасибо

Подробнее здесь: https://stackoverflow.com/questions/793 ... ttpclient4
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»