Bird
0
0

What will be the output when accessing the endpoint defined by this REST controller method?

medium📝 component behavior Q13 of 15
Spring Boot - REST Controllers
What will be the output when accessing the endpoint defined by this REST controller method?
@RestController
public class HelloController {
  @GetMapping("/hello")
  public String sayHello() {
    return "Hello, World!";
  }
}
AA JSON object {"message":"Hello, World!"}
BPlain text response: Hello, World!
CHTTP 404 Not Found error
DAn HTML page with 'Hello, World!' text
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the method return type and annotation

    The method returns a String and is inside a @RestController, so the string is sent as plain text.
  2. Step 2: Understand @RestController behavior

    @RestController automatically adds @ResponseBody, so the return is the response body, not a view or JSON object.
  3. Final Answer:

    Plain text response: Hello, World! -> Option B
  4. Quick Check:

    String return in @RestController = plain text response [OK]
Quick Trick: String return in @RestController sends plain text response [OK]
Common Mistakes:
  • Expecting JSON output without wrapping string in an object
  • Thinking it returns an HTML page
  • Assuming 404 error without mapping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes