I have a lib which is using spring boot web 2.x. When a SpringBoot3.x project uses my lib and invokes its methods, some methods like "response.getStatusCode()" will throw an exception:

java.lang.NoSuchMethodError: 'org.springframework.http.HttpStatusCode org.springframework.http.ResponseEntity.getStatusCode()'

Can you please give me some guidances about how to make my lib support both SpringBoot2.x and SpringBoot3.x project? Thanks.

Comment From: flashvayne

The method that throws Exception in my lib is as below line 2

ResponseEntity<T> responseEntity = restTemplate.postForEntity(url, httpEntity, responseType);
if (responseEntity.getStatusCode().isError()) {
    .........

Comment From: scottfrederick

@flashvayne The ResponseEntity class you are referring to is part of Spring Framework, not Spring Boot. So it is the Spring Framework version that you need to be concerned about. In order to make your library compatible with Spring Framework 5 / Spring Boot 2 and Spring Framework 6 / Spring Boot 3, you'll need to make sure you are only using APIs that are available in both major versions of these libraries. This is difficult to do, which is why most Spring projects release separate major versions that support the Framework and Boot major versions.

You can review the Framework and Boot release notes for more information on the differences between the major versions.

If you have further questions, please follow up on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.