How it works...
The overall flow of the project setup is similar to what has been done in the XML-based Spring MVC project configuration. The only difference is the presence of several configuration classes that can be categorized according to the set of beans they manage and inject. The core configuration class is always given to the root context class, such as the SpringDispatcherConfig, because of its role to register the DispatcherServlet to the servlet container.
The JavaConfig specification has provided the @Configuration annotation to all context definition classes to establish the MVC backbone of the application, which makes it easier than implementing org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.
On the other hand, the setLoadOnStartup() method tells the servlet container about the loading time of the DispatcherServlet, which is by convention set to 1, meaning it must be loaded first.
After a successful DispatcherServlet registration, a WebApplicationContext object is created, waiting for a bean injection from the view resolvers and other MVC-specific components.
On the InternalResourceViewResolver and MessageResourceViewResolver configuration, the JavaConfig approach only requires these beans to use the @Bean annotation during its injections. The rest of the rules on creating physical view pages with their corresponding logical view names are just the same as with the XML-based approach.
In order for the MVC application to finally work, the root context class SpringDispatcherConfig must recognize all these JavaConfig components and JSR-330 annotations through the use of the @EnableWebMvc annotation. And to recognize all MVC components, SpringDispatcherConfig must declare the @ComponentScan annotation with the list of packages including the main root package of the application.