Configuring a Spring MVC Application - Part 2

Learn to perform component scanning, validation, type conversion, and view resolver while creating a Spring MVC application.

In the last lesson, we defined the front controller called dispatcher for our Spring MVC application. We also mapped all requests starting with http://localhost:8080/spring/ to the dispatcher servlet. This servlet will map the incoming requests to different controllers as well as handle the response being sent back to the client. For this purpose, it needs a configuration file.

Dispatcher servlet config file

We will create the dispatcher servlet configuration file called player-servlet.xml in the WEB-INF directory because this is how we configured it in web.xml file, in the previous lesson:

<init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/player-servlet.xml</param-value>
</init-param>

The dispatcher servlet config file will contain the following:

  • Component scanning support
  • Data validation and type conversion support
  • View resolver configuration

Right click on the WEB-INF directory and create an XML file called player-servlet.xml. The file contains metadata defining namespaces as follows:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.