Bird
0
0

What will happen if you send a GET request to a Spring Boot controller method annotated with @PostMapping("/data")?

medium📝 component behavior Q5 of 15
Spring Boot - REST Controllers
What will happen if you send a GET request to a Spring Boot controller method annotated with @PostMapping("/data")?
AThe method executes and returns data
BHTTP 405 Method Not Allowed error
CHTTP 404 Not Found error
DThe server crashes
Step-by-Step Solution
Solution:
  1. Step 1: Understand HTTP method mapping

    @PostMapping only handles POST requests, not GET requests.
  2. Step 2: Identify server response to unsupported method

    Sending a GET request to a POST-only endpoint results in HTTP 405 Method Not Allowed error.
  3. Final Answer:

    HTTP 405 Method Not Allowed error -> Option B
  4. Quick Check:

    GET to @PostMapping = 405 error [OK]
Quick Trick: GET to @PostMapping endpoint causes 405 error [OK]
Common Mistakes:
  • Expecting 404 instead of 405
  • Assuming method runs on GET
  • Thinking server crashes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes