Bird
0
0

Given this controller method:

medium📝 component behavior Q13 of 15
Spring Boot - Request and Response Handling
Given this controller method:
@RequestMapping(path = "/test", method = RequestMethod.POST)
public String test() {
    return "Success";
}
What happens when a client sends a GET request to "/test"?
AThe server crashes with an exception.
BThe method runs and returns "Success".
CSpring returns a 404 Not Found error.
DSpring returns a 405 Method Not Allowed error.
Step-by-Step Solution
Solution:
  1. Step 1: Identify the mapped HTTP method

    The method is mapped only to POST requests at path "/test".
  2. Step 2: Understand what happens on GET request

    A GET request to the same path is not handled, so Spring returns 405 Method Not Allowed.
  3. Final Answer:

    Spring returns a 405 Method Not Allowed error. -> Option D
  4. Quick Check:

    GET to POST-only path = 405 error [OK]
Quick Trick: GET request to POST-only path causes 405 error [OK]
Common Mistakes:
  • Assuming GET runs the POST method
  • Thinking it returns 404 Not Found instead
  • Believing server crashes on wrong method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes