spring 一些概念

我们来看几个容易混淆的用于简化开发的配置: <mvc:annotation-driven />, <context:annotation-config/>, <context:component-scan />。  

        <mvc:annotation-driven /> 会做以下几件事:  
  1. 向 spring 容器中注册 DefaultAnnotationHandlerMapping。
  2. 向 spring 容器中注册 AnnotationMethodHandlerAdapter。
  3. 配置一些 messageconverter。
  4. 解决了 @Controller 注解的使用前提配置,即 HandlerMapping 能够知道谁来处理请求。
        <context:annotation-config /> 会做以下几件事:  
  1. 向 spring 容器中注册 AutowiredAnnotationBeanPostProcessor。
  2. 向 spring 容器中注册 CommonAnnotationBeanPostProcessor。
  3. 向 spring 容器中注册 PersistenceAnnotationBeanPostProcessor。
  4. 向 spring 容器中注册 RequiredAnnotationBeanPostProcessor。
  5. 使用 <context:annotationconfig />之前,必须在 <beans> 元素中声明 context 命名空间 <context:component-scan />。<context:component-scan /> 对包进行扫描,实现注解驱动 Bean 定义。即,将 @Controller 标识的类的 bean 注册到容器中。
        <context:component-scan/>,不但启用了对类包进行扫描以实施注解驱动 Bean 定义的功能,同时还启用了注解驱动自动注入的功能(即还隐式地在内部注册了 AutowiredAnnotationBeanPostProcessor 和 CommonAnnotationBeanPostProcessor)。因此当使用 <context:component-scan /> 后,除非需要使用PersistenceAnnotationBeanPostProcessor 和 RequiredAnnotationBeanPostProcessor 两个 Processor 的功能(例如 JPA 等),否则就可以将 <context:annotation-config /> 移除了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值