Enable MVC Configuration
在 Java 配置中,你可以使用 @EnableWebMvc注解来启用 MVC 配置,如下例所示:
@Configuration@EnableWebMvcpublic class WebConfig {}
在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/beanshttps://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/mvchttps://www.springframework.org/schema/mvc/spring-mvc.xsd"><mvc:annotation-driven/></beans>
前面的例子注册了一些 Spring MVC 基础设施 Bean,并适应 classpath 上可用的依赖关系(例如,JSON、XML 等的有效载荷转换器)。
