question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add native-image support for RestTemplateBuilder

See original GitHub issue

When 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:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mhalbrittercommented, Aug 1, 2022

I decided to not refactor the reflection away and went for the RuntimeHints way instead. I made ClientHttpRequestFactorySupplier more native-friendly by introducting _PRESENT constants.

0reactions
snicollcommented, Nov 15, 2022

Good catch @akefirad, I’ve created #33203

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found