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.

Tutorials

  1. Spring 3.2
  2. New Features of Spring Framework 3.2
  3. Spring MVC framework Introduction
  4. Special Bean Types of WebApplicationContext
  5. Spring MVC framework Features
  6. Processing Sequence of DispatcherServlet
  7. @Controller annotation for defining new controller
  8. @RequestMapping annotation for mapping requests
  9. Spring 3.2 Asynchronous Request Processing
  10. Defining handler methods using @RequestMapping annotation
  11. Requests Intercepting through a HandlerInterceptor
  12. View Resolving through ViewResolver interface
  13. Chaining of Multiple view resolvers
  14. Redirecting and forwarding to views
  15. ContentNegotiatingViewResolver
  16. Locales in Spring MVC
  17. Themes and Theme resolvers in Spring MVC
  18. Multipart support for file upload in Spring MVC
  19. @ExceptionHandler & @ResponseStatus annotation
  20. Customizing the Default Error Page
  21. Form Tag library configuration
  22. The form tag
  23. The input tag
  24. The password tag
  25. ControllerClassNameHandlerMapping class for handling convention mapping
  26. Modification in conventional ModelAndView
  27. Autogenerated logical view name through RequestToViewNameTranslator
  28. The checkbox tag
  29. Support for ETag
  30. Servlet container initialization through code
  31. MVC Java Config or the MVC XML Namespace
  32. Customizing the MVC Java config or XML Namespace
  33. Interceptors Configuration using Java or XML
  34. Content Negotiation Configuration
  35. Spring 3.2 MVC Hello World Example
  36. View resolvers
  37. View Controllers Configuration
  38. Static Resources Configuration
  39. mvc:default-servlet-handler
  40. The checkboxes tag