nerdexam
Broadcom-VMware

2V0-72.22PSE · Question #55

Which two statements are true about @Controller annotated classes? (Choose two.)

The correct answer is B. The classes are eligible for handling requests in Spring MVC. E. The @Controller annotation is a stereotype annotation like @Component. @Controller is a stereotype annotation (like @Component, @Service, @Repository), meaning Spring's component scanning automatically detects and registers it as a bean - that's why E is correct. Being a registered bean, the class becomes eligible to handle HTTP requests in the…

Core Spring

Question

Which two statements are true about @Controller annotated classes? (Choose two.)

Options

  • AThe @Controller annotated classes can only render views.
  • BThe classes are eligible for handling requests in Spring MVC.
  • CThe classes must be annotated together with @EnableMvcMappings to be discovered via
  • D@Controller is interchangeable with @RestController with no extra code changes for the
  • EThe @Controller annotation is a stereotype annotation like @Component.

How the community answered

(59 responses)
  • A
    2% (1)
  • B
    93% (55)
  • C
    3% (2)
  • D
    2% (1)

Explanation

@Controller is a stereotype annotation (like @Component, @Service, @Repository), meaning Spring's component scanning automatically detects and registers it as a bean - that's why E is correct. Being a registered bean, the class becomes eligible to handle HTTP requests in the Spring MVC dispatcher framework, making B correct.

Why the distractors are wrong:

  • A is false - @Controller can also return response body data (e.g., JSON) when methods are annotated with @ResponseBody; it's not limited to views.
  • C is false - no @EnableMvcMappings annotation exists; @Controller classes are discovered through standard component scanning (@ComponentScan or @SpringBootApplication).
  • D is false - @RestController = @Controller + @ResponseBody applied to every method, so switching between them does require code changes (adding or removing @ResponseBody on methods).

Memory tip: Think of @Controller as a specialised @Component - it inherits all the auto-detection benefits of @Component (stereotype), but adds Spring MVC's request-handling awareness. The key difference from @RestController is that @Controller alone won't serialize return values to the response body without @ResponseBody.

Topics

#@Controller#Stereotype annotations#Spring MVC#Component discovery

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22PSE Practice