spring和springmvc父子容器

Posted by     小兵兵 on Thursday, May 28, 2020

目录

spring和springmvc父子容器

image-20200528221022976

包扫描配置

spring配置文件

context:exclude-filter排除Controller上的注解,即@Controllerbean不被扫描

 <context:component-scan base-package="org.xuan.springmvc">
        <context:exclude-filter type="annotation"
                                expression="org.springframework.stereotype.Controller"/>
  </context:component-scan>

springmvc配置文件

use-default-filters="false"禁用默认包扫描,默认为true的话会扫描父容器上的service和dao导致大量重复bean

context:include-filter只扫描Controller上的注解

 <context:component-scan base-package="org.xuan.springmvc.controller"
                            use-default-filters="false">
        <context:include-filter type="annotation"
                                expression="org.springframework.stereotype.Controller"/>
  </context:component-scan>

参考

Spring和SpringMVC父子容器关系初窥

Spring和SpringMVC父子的容器之道—[上篇]

spring与springmvc父子容器