Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facing Issue With HttpStatus in spring boot 3

Currently, I am working on a project to upgrade it to Spring Boot 3, Spring 6, and Java 17. But I am facing an issue with HttpStatus. I have a method that returns HttpStatus.NO_CONTENT and HttpStatus.INTERNAL_SERVER_ERROR.

But it looks like HttpStatus is deprecated in Spring 6 so how can I handle this issue? While building a project with HttpStatus getting compilation error as incompatible types: HttpStatusCode cannot be converted to HttpStatus.

like image 722
sekhar Avatar asked Mar 29 '26 01:03

sekhar


1 Answers

Change it to return an HttpStatusCode instead, e.g.

return HttpStatusCode.valueOf(HttpStatus.NO_CONTENT.value());

HttpStatusCode is an interface that could represent any 3-digit integer, while HttpStatus can only enumerate limited values.

like image 77
Will Phi Avatar answered Apr 02 '26 22:04

Will Phi