Home > Back-end >  Spring boot Rest Controller's Request Path gives 404 Not Found Error
Spring boot Rest Controller's Request Path gives 404 Not Found Error

Time:03-01

I have a problem about send a request through Postman in my Spring Boot app.

I have an AuthController to implement the process of signup, signin and lastly logout.

My problem is related with request pathing.

I used 1221 port in my app.

Here is my controller shown below.

@RestController
@RequestMapping("/api/auth")
public class AuthController {

    @PostMapping("/signup")
    public ResponseEntity<?> registerUser(@RequestBody RegisterRequest registerRequest) {
    }

}

The error appeared when I send this request (http://localhost:1221/api/auth/signup).

{
    "status": 404,
    "error": "Not Found",
    "path": "/api/auth/signup"
}

How can I fix it?

CodePudding user response:

  1. Check if your request is a POST request.
  2. The method contract expects a return value, but it is not in the code. Probably the usual behavior returns 404. Try to add return ResponseEntity.ok().build();
  3. It is possible that some application on your computer is already using port 1221.

CodePudding user response:

There are below possibility are there, 1>Do check your Http Method in the post man Is it post method or other method. 2> Do check your application.properties file if you configure your application name in context path than you need to add that path also, For example http://localhost:1221/app-name/api/auth/signup

CodePudding user response:

Make sure that in postman you set the method to post as you have created a post method handler. Also try returning a ResponseEntity object as this might cause an error.

  • Related