Add native-image support for RestTemplateBuilder
See original GitHub issueWhen using RestTemplateBuilder in a native-image, for example in this code:
private final RestTemplateBuilder restTemplateBuilder;
// ...
RestTemplate restTemplate = this.restTemplateBuilder
.setConnectTimeout(Duration.ofSeconds(5))
.setReadTimeout(Duration.ofSeconds(5))
.build();
then this fails in a native image with this stacktrace:
java.lang.IllegalStateException: Request factory class org.springframework.http.client.SimpleClientHttpRequestFactory does not have a suitable setConnectTimeout method
at org.springframework.boot.web.client.RestTemplateBuilder$RequestFactoryCustomizer.findMethod(RestTemplateBuilder.java:782)
at org.springframework.boot.web.client.RestTemplateBuilder$RequestFactoryCustomizer.setConnectTimeout(RestTemplateBuilder.java:761)
at org.springframework.boot.web.client.RestTemplateBuilder$RequestFactoryCustomizer.accept(RestTemplateBuilder.java:736)
at org.springframework.boot.web.client.RestTemplateBuilder.buildRequestFactory(RestTemplateBuilder.java:656)
at org.springframework.boot.web.client.RestTemplateBuilder.configure(RestTemplateBuilder.java:614)
at org.springframework.boot.web.client.RestTemplateBuilder.build(RestTemplateBuilder.java:589)
at com.example.resttemplate.CLR.http(CLR.java:33)
at com.example.resttemplate.CLR.run(CLR.java:26)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:768)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at com.example.resttemplate.RestTemplateApplication.main(RestTemplateApplication.java:13)
This can be observed in https://ci.spring.io/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/rest-template/builds/1
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
GraalVM Native Image Support - Spring
A GraalVM Native Image is a complete, platform-specific executable. ... So instead, when using Spring Boot to create native images, ...
Read more >Configure a RestTemplate with RestTemplateBuilder - Baeldung
In this quick tutorial, we're going to look at how to configure a Spring RestTemplate bean. Let's start by discussing the three main ......
Read more >spring-projects/spring-boot - Gitter
I am struggling to migrate a Spring Boot 2.x project to 3.x with GraalVM Native Image support. Is it correct in a Gradle...
Read more >Creating Java microservices with Spring Boot and Liberica JDK
Are you currently working to create a network of microservices? We are here to help you with this exciting and challenging process, ...
Read more >Going Native With Spring Boot 3 GA - Better Programming
Native image support is mostly about making it possible for an application and its libraries to analyze at build time to configure what's ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I decided to not refactor the reflection away and went for the
RuntimeHintsway instead. I madeClientHttpRequestFactorySuppliermore native-friendly by introducting_PRESENTconstants.Good catch @akefirad, I’ve created #33203