疑问:
<context:component-scan base-package="com.ppf">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
我写这段代码的意思是只扫描com.ppf
下的@Controller
注解,但实际上是扫描着了com.ppf
下的所有@Component
,@Repository
,@Service
和@Controller
。
为什么?
因为context:component-scan
里还有一个属性要配合使用,use-default-filters
,它的默认值true
use-default-filters的解释
Indicates whether automatic detection of classes annotated with @Component, @Repository, @Service,or @Controller should be enabled. Default is "true".
所以要把 use-default-filters
要设为false
解决:
<context:component-scan base-package="com.ppf" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>