File tree Expand file tree Collapse file tree
spring-mvc-custom-status-codes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ * .class
2+
3+ # folders#
4+ /target
5+ /neoDb *
6+ /data
7+ /src /main /webapp /WEB-INF /classes
8+ * /META-INF /*
9+
10+ # Packaged files #
11+ * .jar
12+ * .war
13+ * .ear
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3+ xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
4+ <modelVersion >4.0.0</modelVersion >
5+
6+ <groupId >com.baeldung</groupId >
7+ <artifactId >custom-status-codes</artifactId >
8+ <version >0.0.1-SNAPSHOT</version >
9+ <packaging >jar</packaging >
10+
11+ <name >spring-mvc-custom-status-codes</name >
12+ <description >Returning Custom Status Codes from Spring MVC Controllers</description >
13+
14+ <parent >
15+ <groupId >org.springframework.boot</groupId >
16+ <artifactId >spring-boot-starter-parent</artifactId >
17+ <version >1.3.2.RELEASE</version >
18+ <relativePath /> <!-- lookup parent from repository -->
19+ </parent >
20+
21+ <properties >
22+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
23+ <java .version>1.8</java .version>
24+ </properties >
25+
26+ <dependencies >
27+ <dependency >
28+ <groupId >org.springframework.boot</groupId >
29+ <artifactId >spring-boot-starter-web</artifactId >
30+ <version >1.3.2.RELEASE</version >
31+ </dependency >
32+ </dependencies >
33+
34+ <build >
35+ <plugins >
36+ <plugin >
37+ <groupId >org.springframework.boot</groupId >
38+ <artifactId >spring-boot-maven-plugin</artifactId >
39+ </plugin >
40+ </plugins >
41+ </build >
42+
43+
44+ </project >
Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+
6+ @ SpringBootApplication
7+ public class CustomStatusCodesApplication {
8+ public static void main (String [] args ) {
9+ SpringApplication .run (CustomStatusCodesApplication .class , args );
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ import org .springframework .http .HttpStatus ;
4+ import org .springframework .http .ResponseEntity ;
5+ import org .springframework .stereotype .Controller ;
6+ import org .springframework .web .bind .annotation .RequestMapping ;
7+ import org .springframework .web .bind .annotation .RequestMethod ;
8+ import org .springframework .web .bind .annotation .ResponseBody ;
9+
10+ @ Controller
11+ public class ExampleController {
12+
13+ @ RequestMapping (value = "/controller" , method = RequestMethod .GET )
14+ @ ResponseBody
15+ public ResponseEntity sendViaResponseEntity () {
16+ return new ResponseEntity (HttpStatus .NOT_ACCEPTABLE );
17+ }
18+
19+ @ RequestMapping (value = "/exception" , method = RequestMethod .GET )
20+ @ ResponseBody
21+ public ResponseEntity sendViaException () {
22+ throw new ForbiddenException ();
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ import org .springframework .http .HttpStatus ;
4+ import org .springframework .web .bind .annotation .ResponseStatus ;
5+
6+ @ ResponseStatus (value = HttpStatus .FORBIDDEN , reason ="To show an example of a custom message" )
7+ public class ForbiddenException extends RuntimeException {
8+
9+ }
You can’t perform that action at this time.
0 commit comments