zoukankan      html  css  js  c++  java
  • Spring自定义如何扫描

    Using filters to customize scanning

    By default, classes annotated with @Component, @Repository, @Service, @Controller, or a custom annotation that itself is annotated with @Component are the only detected candidate components. However, you can modify and extend this behavior simply by applying custom filters. Add them as include-filter or exclude-filter sub-elements of the component-scan element. Each filter element requires the type and expression attributes. The following table describes the filtering options.

    Table 3.5. Filter Types

    Filter TypeExample ExpressionDescription
    annotation org.example.SomeAnnotation An annotation to be present at the type level in target components.
    assignable org.example.SomeClass A class (or interface) that the target components are assignable to (extend/implement).
    aspectj org.example..*Service+ An AspectJ type expression to be matched by the target components.
    regex org\.example\.Default.* A regex expression to be matched by the target components class names.
    custom org.example.MyTypeFilter A custom implementation of the org.springframework.core.type .TypeFilter interface.

    The following example shows the XML configuration ignoring all @Repository annotations and using "stub" repositories instead.

    <beans>
    
       <context:component-scan base-package="org.example">
          <context:include-filter type="regex" expression=".*Stub.*Repository"/>
          <context:exclude-filter type="annotation"
                                  expression="org.springframework.stereotype.Repository"/>
       </context:component-scan>
    
    </beans>
    [Note] Note

    You can also disable the default filters by providing use-default-filters="false" as an attribute of the <component-scan/> element. This will in effect disable automatic detection of classes annotated with @Component, @Repository, @Service, or @Controller.

    详见:

    http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-scanning-filters

  • 相关阅读:
    lib-qqwry v1.0 发布 nodejs解析纯真IP库(qqwry.dat)
    queue-fun —— nodejs下基于Promise的队列控制模块。
    javascript 高效按字节截取字符串
    最短JS判断是否为IE6(IE的写法) (转)
    javascript把IP地址转为数值几种方案,来挑战一下效率吧
    Android的ViewPager的学习
    【感悟】一次不太好的寻找bug的体验,RecyclerView
    Android的SQlite的使用
    Android的几种Manager
    Android的Service的创建与使用
  • 原文地址:https://www.cnblogs.com/oceanking/p/2532555.html
Copyright © 2011-2022 走看看