Этот код совместим с Spring Boot 2.7.10. Какие изменения мне нужно внести в код ниже, чтобы сделать его совместимым с Spring Boot 3.3.0?
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets;
@Component
public class RestConfig {
@Bean(name = "restTemplate")
private RestTemplate restTemplate() {
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create()
.setMaxConnPerRoute(40)
.setMaxConnTotal(150)
.build());
httpRequestFactory.setConnectionRequestTimeout(5000);
httpRequestFactory.setConnectTimeout(3000);
httpRequestFactory.setReadTimeout(50000);
RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
restTemplate.getMessageConverters()
.add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));
return restTemplate;
}
}
Обновление: добавлены файлы pom.xml.
pom.xml для весенней загрузки 2.7.10:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.7.10
org.example
demo
0.0.1-SNAPSHOT
demo
demo
17
org.springframework.boot
spring-boot-starter-web
org.apache.httpcomponents
httpclient
4.5.13
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
pom.xml для весенней загрузки 3.3.0:
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.3.0
org.example
demo
0.0.1-SNAPSHOT
demo
demo
17
org.springframework.boot
spring-boot-starter-web
org.apache.httpcomponents.client5
httpclient5
5.3.1
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
Подробнее здесь: https://stackoverflow.com/questions/793 ... boot-3-3-0
RestTemplate в Spring boot 3.3.0 ⇐ JAVA
Программисты JAVA общаются здесь
1737298619
Anonymous
Этот код совместим с Spring Boot 2.7.10. Какие изменения мне нужно внести в код ниже, чтобы сделать его совместимым с Spring Boot 3.3.0?
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets;
@Component
public class RestConfig {
@Bean(name = "restTemplate")
private RestTemplate restTemplate() {
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create()
.setMaxConnPerRoute(40)
.setMaxConnTotal(150)
.build());
httpRequestFactory.setConnectionRequestTimeout(5000);
httpRequestFactory.setConnectTimeout(3000);
httpRequestFactory.setReadTimeout(50000);
RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
restTemplate.getMessageConverters()
.add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));
return restTemplate;
}
}
Обновление: добавлены файлы pom.xml.
pom.xml для весенней загрузки 2.7.10:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.7.10
org.example
demo
0.0.1-SNAPSHOT
demo
demo
17
org.springframework.boot
spring-boot-starter-web
org.apache.httpcomponents
httpclient
4.5.13
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
pom.xml для весенней загрузки 3.3.0:
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.3.0
org.example
demo
0.0.1-SNAPSHOT
demo
demo
17
org.springframework.boot
spring-boot-starter-web
org.apache.httpcomponents.client5
httpclient5
5.3.1
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
Подробнее здесь: [url]https://stackoverflow.com/questions/79368116/resttemplate-in-spring-boot-3-3-0[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия