I'm upgrading my main application from Spring Boot 2.x to 3.x.
The upgrade is mostly successful, except for a runtime compatibility issue caused by 3rd-party or legacy internal libraries that still depend on Spring Boot 2.x and the RestTemplate API.
Context:
My main application now uses:
- Spring Boot:
3.x - Spring Framework:
6.x - JDK:
17
- Spring Boot:
However, I have hundreds of shared SDKs/libraries (some internal, some 3rd-party) that:
- Are compiled against Spring Boot 2.x
- Use
org.springframework.web.client.RestTemplate - Internally call:
expecting it to returnorg.springframework.http.client.ClientHttpResponse#getStatusCode()org.springframework.http.HttpStatus.
After upgrading, I’m getting the following error during runtime:
java.lang.NoSuchMethodError: ‘org.springframework.http.HttpStatus org.springframework.http.client.ClientHttpResponse.getStatusCode()
This happens inside a ClientHttpRequestInterceptor in one of the legacy SDKs that I cannot modify.
Here’s a snippet from the stack trace:
Caused by: java.lang.NoSuchMethodError: ‘org.springframework.http.HttpStatus org.springframework.http.client.ClientHttpResponse.getStatusCode()’
at com.legacy.sdk.interceptor.LegacyInterceptor.intercept(LegacyInterceptor.java:46)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:900)
This makes sense because Spring Framework 6.x changed the method signature:
Old (Spring Boot 2.x / Framework 5.x): HttpStatus ClientHttpResponse.getStatusCode();
New (Spring Boot 3.x / Framework 6.x): HttpStatusCode ClientHttpResponse.getStatusCode();
The old method was removed (not deprecated), so libraries expecting the old signature will crash.
Additional Details
- I cannot update these legacy libraries immediately — some are external, some very deeply integrated.
- I’ve already migrated my own code to use
RestClientinstead ofRestTemplate. - However, legacy dependencies still use
RestTemplate, and I can’t change them.
Is there any official or community-recommended strategy to run Spring Boot 2.x compiled SDKs (that rely on deprecated/removed methods like ClientHttpResponse#getStatusCode()) inside a Spring Boot 3 application?
WebSecurityConfigurerAdapter. The same version of some code isn't expected to work with both Spring 5 and 6.HttpStatus(which infact is still being returned) now implements an interface. That interface is theHttpStatusCode. This change was introduced to allow for customized HTTP return codes. So you could write a piece of code which does reflection to extract theHttpStatusenum (either directly or through a cast). So you probably can make it work but that would require some work. That being said that change has been made 3 years ago, so that you run into it now is also a bit on your side that you took that long to upgrade.