•當在組件類上使用了特定的註解以後, 還須要在 Spring 的配置文件中聲明 <context:component-scan> :spring
–base-package 屬性指定一個須要掃描的基類包,Spring 容器將會掃描這個基類包裏及其子包中的全部類.express
–當須要掃描多個包時, 可使用逗號分隔.component
–若是僅但願掃描特定的類而非基包下的全部類,可以使用 resource-pattern 屬性過濾特定的類,示例:繼承
–<context:include-filter> 子節點表示要包含的目標類資源
–<context:exclude-filter> 子節點表示要排除在外的目標類it
–<context:component-scan> 下能夠擁有若干個 <context:include-filter> 和 <context:exclude-filter> 子節點io
•<context:include-filter> 和 <context:exclude-filter> 子節點支持多種類型的過濾表達式:class
<!-- 掃描該包下的全部 -->
<!-- <context:component-scan base-package="com.auotwrite"></context:component-scan> -->容器
<!-- resource-pattern 指定掃描的資源 -->
<!-- <context:component-scan base-package="com.auotwrite" resource-pattern="respo/*.class"></context:component-scan> -->配置
<!-- 子節點表示指定要排除在外的目標類 -->
<!-- <context:component-scan base-package="com.auotwrite">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan> -->
<!-- 子節點表示指定要包含的目標類 該方法需配合 use-default-filters 屬性使用 -->
<!-- <context:component-scan base-package="com.auotwrite"
use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan> -->
<!-- 子節點表示指定要排除的繼承該類的目標 關鍵屬性:type="assignable -->
<!-- <context:component-scan base-package="com.auotwrite">
<context:exclude-filter type="assignable" expression="com.auotwrite.respo.CarProI"/>
</context:component-scan> -->
<!-- 子節點表示指定要包含的繼承該類的目標 關鍵屬性 :type="assignable 注意:需配合 use-default-filters 屬性使用 --> <context:component-scan base-package="com.auotwrite" use-default-filters="false"> <context:include-filter type="assignable" expression="com.auotwrite.respo.CarProI"/> </context:component-scan>