Bird
0
0

What is wrong with this Spring Boot controller method that causes it to not handle requests properly?

medium📝 Debug Q14 of 15
Spring Boot - Request and Response Handling
What is wrong with this Spring Boot controller method that causes it to not handle requests properly?
@GetMapping("/data")
public void getData() {
    System.out.println("Data requested");
}
ASystem.out.println cannot be used inside controller methods.
BThe @GetMapping annotation is missing parentheses.
CThe method returns void, so no response is sent to the client.
DThe method should be private, not public.
Step-by-Step Solution
Solution:
  1. Step 1: Check the method return type and response behavior

    The method returns void and does not write to the response, so the client gets no content.
  2. Step 2: Understand HTTP response requirements

    Controllers must return a response body or view; void means no response, causing client issues.
  3. Final Answer:

    The method returns void, so no response is sent to the client. -> Option C
  4. Quick Check:

    Void return means no client response = D [OK]
Quick Trick: Controller methods must return response, not void [OK]
Common Mistakes:
  • Thinking @GetMapping needs no parentheses
  • Believing method visibility causes error
  • Assuming System.out.println breaks controller

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes