Is RestTemplate compatible with Spring Boot 3?

7.1k Views Asked by At

I'm trying to upgrade a legacy application to spring boot 3 and RestTemplate is used extesibly.

As far as I know Spring Boot 3 doesn't allow blocking code (at least by default) and I was wondering if this behavior could be changed or the only solution is to ditch RestTemplate and reimplement everything with WebClient?

So far I replaced a call that used rest template to use WebClient instead, but I couldn't find any answers to my question on the web

Edit:

This error is what led me to believe that RestTemplate was not compatible with Spring Boot 3 (the code the caused this exception worked fine before the upgrade).

java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-2
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83) ~[reactor-core-3.4.3.jar:3.4.3]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 

Is it possible that by upgrading to Spring Boot 3 jetty/undertow was picked instead of tomcat?

1

There are 1 best solutions below

0
On

You can still use RestTemplate in spring boot 3 project. It is just in the maintenance mode. Only minor request for the changes and bugs will be accepted going forward.

Spring boot 3 requires Spring Framework 6. The fact that you can still find RestTemplate from Spring Framework 6 already told you that it is compatible with Spring boot 3.

As far as I know Spring Boot 3 doesn't allow blocking code (at least by default)

Also this is not true. Not sure where do you get such information. For example , you can still use Hibernate in Spring Boot 3 which uses blocking IO to interact with DB.