Controllers are the Presentation layer components that are responsible for responding to the user's actions. These actions could be entering a particular URL in the browser, clicking on a link, submitting a form on a web page, or something similar. Any regular Java classes can be transformed into a Controller by simply annotating them with the @Controller
(org.springframework.stereotype.Controller
) annotation.
And as you have already learned, the @Controller
annotation supports Spring's component scanning mechanism in auto-detecting/registering the bean definition in the web application's context. To enable this auto-registering capability, we must add the @ComponentScan
(org.springframework.context.annotation.ComponentScan
) annotation in the web application context configuration file. You saw how to do this in
Chapter 2, Spring MVC Architecture – Architecting Your Web Store under the section Understanding the web application context configuration.
A Controller class...