配置MVC的两种方式【mvc:annotation-driven】

配置使用MVC的两种方式【注解】以及【XML】

注解方式【EnableWebMvc】

在Configuration注解的类中,使用EnableWebMvc以启用MVC 配置

1 @Configuration
2 @EnableWebMvc
3 public class WebConfig {
4 
5 }

XML方式【mvc:annotation-driven】

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:mvc="http://www.springframework.org/schema/mvc"
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5     xsi:schemaLocation="
 6         http://www.springframework.org/schema/beans
 7         http://www.springframework.org/schema/beans/spring-beans.xsd
 8         http://www.springframework.org/schema/mvc
 9         http://www.springframework.org/schema/mvc/spring-mvc.xsd">
10 
11     <mvc:annotation-driven/>
12 
13 </beans>

作用

上述配置作用一致,都是注册了Bean,RequestMappingHandlerMapping,RequestMappingHandlerAdapter,ExceptionHandlerExceptionResolver

以上bean都是用来使用@RequestMapping@ExceptionHandler等注解来处理Controller中的方法。

在老的版本中,是自动注册DefaultAnnotationHandlerMapping 与AnnotationMethodHandlerAdapter 这两个bean,但Spring在版本3.2中已经废弃两个类。

并通过文档得知,其注册的是上述三个类。

转载于:https://www.cnblogs.com/may-cn/p/6118451.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值