context:component-scan

Spring中applicationContext.xml中有个标签<context:component-scan>通过扫描文件的方式进行注入。

使用<context:component-scan>之后<context:annotation-conf>标签就没什么用了,因为<context:component-scan>标签已经包含了注释扫描功能

具体使用如下:

<context:component-scan base-package="com.foo" use-default-filters="false">
    <context:include-filter type="regex" expression="com.foo.bar.*Config"/>
    <context:include-filter type="regex" expression="com.foo.config.*"/>
</context:component-scan>

context:component-scan>有两个子标签:<context:include-filter/>和<context:exclude-filter/>分别表示引入和排除注入的过滤

子标签的type属性的取值有:

Filter TypeExamples ExpressionDescription
annotationorg.example.SomeAnnotation符合SomeAnnoation的target class 根据注释
assignableorg.example.SomeClass指定class或interface的全名
aspectjorg.example..*Service+AspectJ語法
regexorg\.example\.Default.*Regelar Expression
customorg.example.MyTypeFilterSpring3新增自訂Type,實作org.springframework.core.type.TypeFilter


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值