PostMapping annotation causes a whitelabel error page in SpringBoot

I'm new to Java and react web development and I'm having an issue with my postBody method. After sending a post request, the console prints the data posted from my frontend correctly, but it shows a whitelabel error page that says (type=Not Found, status=404) in localhost:8080/api and (type=Method Not Allowed, status=405) in localhost:8080/api/data. Below is the HelloController code. package com.java.java.practice; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.http.MediaType; import org.springframework.web.cors.CorsConfiguration; import java.util.ArrayList; import java.util.Arrays; import java.util.Map; @RestController @RequestMapping("/api") public class HelloController { //this performes a post and get request @CrossOrigin(origins = "http://localhost:3000/api") @PostMapping(value="/n", consumes = MediaType.APPLICATION_JSON_VALUE) public String postBody(@RequestBody String fullName) { System.out.println(fullName); return "Hello " + fullName; //returns response } } Below is the main application package com.java.java.practice; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @ComponentScan(basePackages="com.java.java.practice") public class PracticeApplication { public static void main(String[] args) { SpringApplication.run(PracticeApplication.class, args); } } The weird thing is, when I replace my HelloController code with the one posted underneath, the whitelabel page goes away and shows text on the screen. package com.java.java.practice; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.http.MediaType; import org.springframework.web.cors.CorsConfiguration; import java.util.ArrayList; import java.util.Arrays; import java.util.Map; @RestController public class HelloController { //this performes a post and get request @CrossOrigin(origins = "http://localhost:3000/api") @RequestMapping("/api") public String postBody() { return "Hello"; //returns response } } Any help would be much appreciated.


I can see a few issues as below, When you try to call via a web browser it's always calling as HTTP GET. But in your RestController, there is no GET method. It only has a POST method. Try to use Postman or CURL to call post method instead of GET. Your URL is wrong. Since you appending /n for the PostMapping annotation it should be (http://localhost:3000/api/n) Only you want fullName as request body try to use PathVariable instead. No point to use RequestBody only for 1 parameter. Sample code as below. @PostMapping(value="/{fullName}", consumes = MediaType.APPLICATION_JSON_VALUE) public String postBody(@PathVariable String fullName) { System.out.println(fullName); return "Hello " + fullName; //returns response }