This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Framework 6.2.0! |
Enable MVC Configuration
You can use the @EnableWebMvc
annotation to enable MVC configuration with programmatic configuration, or <mvc:annotation-driven>
with XML configuration, as the following example shows:
-
Java
-
Kotlin
-
Xml
@Configuration
@EnableWebMvc
public class WebConfiguration {
}
@Configuration
@EnableWebMvc
class WebConfiguration {
}
<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
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven/>
</beans>
When using Spring Boot, you may want to use @Configuration classes of type WebMvcConfigurer but without @EnableWebMvc to keep Spring Boot MVC customizations. See more details in the MVC Config API section and in the dedicated Spring Boot documentation.
|
The preceding example registers a number of Spring MVC infrastructure beans and adapts to dependencies available on the classpath (for example, payload converters for JSON, XML, and others).