springmvc 注解使用的小总结

1 <context:annotation-config />

作用:注册AutowiredAnnotationBeanPostProcessorCommonAnnotationBeanPostProcessorPersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor  BeanPostProcessor

注册这4 BeanPostProcessor的作用,就是为了你的系统能够识别相应的注解.

2 <context:component-scan base-package=""/>:包含了context:annotation-config 的功能,同时能指定扫描路径。因此当使用 <context:component-scan/> 后,除非需要使用PersistenceAnnotationBeanPostProcessor和equiredAnnotationBeanPostProcessor两个Processor的功能(例如JPA等)否则就可以将 <context:annotation-config/> 移除了。

3 <mvc:annotation-driven />

DefaultAnnotationHandlerMapping
用来解析Spring MVC里面的annotation对应的Controller,也就是通过这个类,给annotation设置映射关系,如@RequestMapping等,主要方法determineUrlsForHandlerMethods(Class<?> handlerType, final boolean hasTypeLevelMapping)
AnnotationMethodHandlerAdapter
对Annotation搜索设置的方法进行处理的类,通过此类,解析annotation设置的类的处理,也就是有请求时,通过此类,可以调用annotation设置controller的方法,主要处理方法,handle(HttpServletRequest req, HttpServletResponse resp, Object handler)。

<mvc:annotation-driven/>相当于注册了DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个bean,配置一些messageconverter。即解决了@Controller注解的使用前提配置。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值