MVC Java Config or the MVC XML Namespace

In this section, you will learn about two different way for configuring Spring MVC : MVC Java Config or the MVC XML Namespace.

MVC Java Config or the MVC XML Namespace

MVC Java Config or the MVC XML Namespace

In this section, you will learn about two different way for configuring Spring MVC : MVC Java Config or the MVC XML Namespace.

For configuring Spring MVC, we have two additional ways : MVC Java config and the MVC XML namespace. These two ways provide the same type of configuration that overrides the DispatcherServlet defaults. You can choose either MVC Java config or MVC XML namespace according to your preference.

Append the annotation @EnableWebMvc to your @Configuration classes to enable the MVC Java config, as shown below :

@Configuration
@EnableWebMvc
public class MyWebAppConfig {

}

To accomplish the same, configure the element mvc:annotation-driven as shown below :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

	<mvc:annotation-driven />

</beans>

The above configuration registers a RequestMappingHandlerMapping, a RequestMappingHandlerAdapter, and an ExceptionHandlerExceptionResolver which provide support to annotated controller methods for handling request processing.