-
use-default-filters = “true”:表示默认扫描所有包,即controller,mapper,service等等,默认为true,一般在spring.xml里面与exclude-filter搭配使用,达到不注入controller的效果(一般在springMVC.xml里配置扫描controller,在这里排除以避免重复扫描)
-
use-default-filters = "false"与include-filter在springMVC.xml里面搭配使用,限制只扫描controller,同样避免重复扫描
-
springMVC.xml配置文件中配置只扫描controller
<context:component-scan base-package="only.mxb.traindemo.controller" use-default-filters="false">
<!-- 只扫描控制器 -->
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation"
expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
- spring.xml文件配置文件中配置不扫描controller
<context:component-scan base-package="only.mxb.traindemo">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation"
expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>