zoukankan      html  css  js  c++  java
  • context:component-scan扫描使用的use-default-filters

      如下方式可以成功扫描到@Controller注解的Bean,不会扫描@Service/@Repository的Bean。

    <context:component-scan base-package="xx.xx.xx.controller">   
         <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>   
    </context:component-scan>

      但是如下方式,不仅仅扫描@Controller,还扫描@Service/@Repository的Bean,可能造成一些问题

      此处只应该加载表现层组件,如果此处还加载dao层或service层的bean会将之前容器加载的替换掉,而且此处不会进行AOP织入,所以会造成AOP失效问题(如事务不起作用)。

    <context:component-scan base-package="xx.xx.xx">   
         <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>   
    </context:component-scan>  

      注意:xx.xx.xx包下可能包括controller、service等。

      <context:component-scan>的use-default-filters属性,则默认为true。ClassPathBeanDefinitionScanner会自动注册对@Component、@ManagedBean、@Named注解的Bean进行扫描。

      在进行扫描时会通过include-filter/exclude-filter来判断你的Bean类是否是合法的:即首先通过exclude-filter 进行黑名单过滤;然后通过include-filter 进行白名单过滤;否则默认排除。

      所以不需要扫描@Service/@Repository的Bean,则use-default-filters=“false”禁用掉。

       参考博客:http://jinnianshilongnian.iteye.com/blog/1423971

  • 相关阅读:
    当年的笔记_apache配置虚拟主机
    sqlserver 调优(三)
    bat命令自用其(一)
    Always On主辅延迟相关描述
    sqlserver中常用的windows命令行的操作
    mysql复制以及一主多从等常见集群概述
    sqlserver 调优(二)
    sqlserver 获取实例上用户数据库的数据字典
    sqlserver事务隔离小结
    mysql 慢查询的小结
  • 原文地址:https://www.cnblogs.com/lcngu/p/5714673.html
Copyright © 2011-2022 走看看