Bird
0
0

Given this Spring Boot controller method, what will be the response when a GET request is made to /hello?

medium📝 component behavior Q13 of 15
Spring Boot - Request and Response Handling
Given this Spring Boot controller method, what will be the response when a GET request is made to /hello?
@GetMapping("/hello")
public String sayHello() {
    return "Hello, Spring!";
}
AThe plain text 'Hello, Spring!' as the HTTP response body
BA JSON object with message 'Hello, Spring!'
CA redirect to another URL
DAn error because no ResponseEntity is returned
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the controller method return type

    The method returns a String, which by default is sent as plain text in the HTTP response body.
  2. Step 2: Understand Spring Boot default behavior for String returns

    Without annotations like @ResponseBody missing, Spring Boot treats String return as response content, not a view name.
  3. Final Answer:

    The plain text 'Hello, Spring!' as the HTTP response body -> Option A
  4. Quick Check:

    String return sends plain text response = B [OK]
Quick Trick: String return sends plain text unless annotated otherwise [OK]
Common Mistakes:
  • Assuming it returns JSON automatically
  • Expecting a redirect without code
  • Thinking ResponseEntity is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes