Spring @ResponseStatus Annotation Example
In this section we will learn about @ResponseStatus Annotation. The @ResponseStatus marks a method or exception class with the status code and reason message that should be returned. The status code is applied to the HTTP response when the handler method is invoked, or whenever the specified exception is thrown. It overrides status information set by other means, like ResponseEntity or redirect. Here is a sample code snippet: @ResponseStatus ( value = HttpStatus . NOT_FOUND ) public class UserNotFoundException extends RuntimeException { } The following example creates a Spring Boot web application which uses @ResponseStatus annotation . Project Directory Pom.xml <? xml version ="1.0" encoding ="UTF-8" ?> < project xmlns ="http://maven.apache.org/POM/4.0.0" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation ="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0....