-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Not planned
Labels
status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid
Description
Spring boot version: 3.x
Cannot instantiate RestTemplate
with HttpComponentsClientHttpRequestFactory
, it raises
Caused by: java.lang.IllegalStateException: Request factory org.springframework.http.client.HttpComponentsClientHttpRequestFactory has the setReadTimeout method marked as deprecated
at org.springframework.util.Assert.state(Assert.java:97) ~[spring-core-6.0.9.jar:6.0.9]
at org.springframework.boot.web.client.ClientHttpRequestFactories$Reflective.findMethod(ClientHttpRequestFactories.java:318) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.web.client.ClientHttpRequestFactories$Reflective.setReadTimeout(ClientHttpRequestFactories.java:303) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.web.client.ClientHttpRequestFactories$Reflective.lambda$configure$1(ClientHttpRequestFactories.java:276) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.context.properties.PropertyMapper$Source.to(PropertyMapper.java:294) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.web.client.ClientHttpRequestFactories$Reflective.configure(ClientHttpRequestFactories.java:276) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.web.client.ClientHttpRequestFactories$Reflective.get(ClientHttpRequestFactories.java:267) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.web.client.ClientHttpRequestFactories.get(ClientHttpRequestFactories.java:130) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.web.client.RestTemplateBuilder.lambda$requestFactory$1(RestTemplateBuilder.java:324) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.web.client.RestTemplateBuilder.buildRequestFactory(RestTemplateBuilder.java:663) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.web.client.RestTemplateBuilder.configure(RestTemplateBuilder.java:629) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.web.client.RestTemplateBuilder.build(RestTemplateBuilder.java:604) ~[spring-boot-3.1.0.jar:3.1.0]
at com.example.demo.RestTemplateConfig.restTemplate(RestTemplateConfig.java:28) ~[classes/:na]
at com.example.demo.RestTemplateConfig$$SpringCGLIB$$0.CGLIB$restTemplate$0(<generated>) ~[classes/:na]
at com.example.demo.RestTemplateConfig$$SpringCGLIB$$2.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258) ~[spring-core-6.0.9.jar:6.0.9]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-6.0.9.jar:6.0.9]
at com.example.demo.RestTemplateConfig$$SpringCGLIB$$0.restTemplate(<generated>) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:139) ~[spring-beans-6.0.9.jar:6.0.9]
... 20 common frames omitted
It seems related to this ticket #32857 but the error still occours
Demo:
demo.zip
Metadata
Metadata
Assignees
Labels
status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
wilkinsona commentedon May 30, 2023
You are providing the request factory which forces an attempt to configure it reflectively. The problem will not occur if you allow Spring Boot to configure things for you:
detomarco commentedon Jun 17, 2023
@wilkinsona I tried your option but when I try to log the response in an interceptor
response.body.apply { mark(available()) } log.debug (response.body.reader().readText() ) response.body.reset()
I get this error
Caused by: java.io.IOException: mark/reset not supported
while they were supported in a previous version
wilkinsona commentedon Jun 18, 2023
Your sample didn't use an interceptor so I'd missed that requirement. Try this instead:
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.