Bird
0
0

How can you define a base path /api/v2 and override it for a specific method to respond at /special (not under base path) in the same controller?

hard📝 Application Q9 of 15
Spring Boot - REST Controllers
How can you define a base path /api/v2 and override it for a specific method to respond at /special (not under base path) in the same controller?
AUse @RequestMapping("/api/v2") at class and @RequestMapping("/special") at method with full path
BUse @RequestMapping("/api/v2") at class and @RequestMapping("special") at method without slash
CUse @RequestMapping("/api/v2") at class and @RequestMapping(path = "/api/v2/special") at method
DUse @RequestMapping("/api/v2") at class and @RequestMapping(path = "/special", absolute = true) at method
Step-by-Step Solution
Solution:
  1. Step 1: Understand default path concatenation

    By default, method paths append to class base path.
  2. Step 2: Override base path by using absolute path

    If method path starts with '/', it is treated as absolute and does not append to base path.
  3. Step 3: Apply to example

    Class has @RequestMapping("/api/v2") and method has @RequestMapping("/special") which overrides base path.
  4. Final Answer:

    Use @RequestMapping("/api/v2") at class and @RequestMapping("/special") at method with full path -> Option A
  5. Quick Check:

    Leading '/' in method path overrides base path [OK]
Quick Trick: Leading '/' in method path overrides base path [OK]
Common Mistakes:
  • Assuming method path always appends base path
  • Using relative path without slash to override
  • Using non-existent 'absolute' attribute

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes