Bird
0
0

Given the following code, what will be the output when accessing /hello endpoint?

medium📝 component behavior Q13 of 15
Spring Boot - REST Controllers
Given the following code, what will be the output when accessing /hello endpoint?
@RestController
public class HelloController {
    @GetMapping("/hello")
    public String sayHello() {
        return "Hello, Spring!";
    }
}
AAn HTML page displaying "Hello, Spring!"
BA plain text response with the string "Hello, Spring!"
CA 404 Not Found error
DA compilation error due to missing annotations
Step-by-Step Solution
Solution:
  1. Step 1: Understand @RestController behavior

    @RestController returns the method's return value directly as the response body, usually JSON or plain text.
  2. Step 2: Analyze the method return

    The method returns a String "Hello, Spring!" which will be sent as plain text in the response body.
  3. Final Answer:

    A plain text response with the string "Hello, Spring!" -> Option B
  4. Quick Check:

    @RestController + String return = plain text response [OK]
Quick Trick: @RestController returns method data as response body [OK]
Common Mistakes:
  • Expecting an HTML page instead of data
  • Thinking it causes 404 without mapping
  • Assuming compilation error without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes