<context:include-filter> 无效?

疑问:

<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>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。