疑问:
<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>









网友评论