I'm following a tutorial about Spring MVC and I cannot understand something about the @ComponentScan
annotation even after reading the spring API doc, so here is the sample code:
Configuring View Controllers
package com.apress.prospringmvc.bookstore.web.config;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
// Other imports ommitted
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.apress.prospringmvc.bookstore.web" })
public class WebMvcContextConfiguration extends WebMvcConfigurerAdapter {
// Other methods ommitted
@Override
public void addViewControllers(final ViewControllerRegistry registry) {
registry.addViewController("/index.htm").setViewName("index");
}
}
Annotation-based Controllers
package com.apress.prospringmvc.bookstore.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class IndexController {
@RequestMapping(value = "/index.htm")
public ModelAndView indexPage() {
return new ModelAndView("index");
}
}
My question is, for View Controllers, by adding @Configuration
and @ComponentScan(basePackages = { "com.apress.prospringmvc.bookstore.web" })
, what will be done in the background? Will the package com.apress.prospringmvc.bookstore.web
offer something for these view controllers?