美文网首页
无效?

无效?

作者: 轻云绿原 | 来源:发表于2020-07-08 11:07 被阅读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>
    

    相关文章

      网友评论

          本文标题: 无效?

          本文链接:https://www.haomeiwen.com/subject/psvqcktx.html