6、spring component-scan掃描 context:exclude-filter 與 context:include-filter
阿新 • • 發佈:2019-02-09
1 在主容器中(applicationContext.xml),將Controller的註解打消掉
<context:component-scan base-package="exampleBean">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
2 在主容器中(applicationContext.xml),按正則過濾指定類
<context:component-scan base-package="exampleBean">
<!-- 過濾掉exampleBean下的且類名以Default開頭的類 -->
<context:exclude-filter type="regex"
expression="exampleBean\.Default*" />
</context:component-scan>
3 在主容器中(applicationContext.xml),按指定類名過濾指定類
<context:component-scan base-package="exampleBean">
<!-- 過濾掉exampleBean下的類名為<span style="font-family: Arial, Helvetica, sans-serif;">MovieFinder</span>的類 -->
<context:exclude-filter type="assignable" expression="exampleBean.MovieFinder"/>
</context:component-scan>