一、在Java配置中,您可以使用@EnableWebMvc批注来启用MVC配置,如以下示例所示:
@Configuration
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {
}
二、在XML配置中,您可以使用该mvc:annotation-driven元素启用MVC配置,如以下示例所示:
<?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
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>