无效?

2020-07-08  本文已影响0人  轻云绿原

疑问:

<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>
上一篇 下一篇

猜你喜欢

热点阅读