spring和springmvc注入ioc的关系

六眼飞鱼酱① 提交于 2019-12-09 02:35:53

spring 是父容器  springmvc是子容器。   子容器可以访问父容器,但父容器不能访问子容器

SpringMVC内的Bean可以使用@Autowire注入Spring容器管理的Bean,反之不行

 

在主容器中(applicationContext.xml),将Controller的注解排除掉 
<context:component-scan base-package="com"> 
  <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 
</context:component-scan> 

而在springMVC配置文件中
<context:component-scan base-package="com" use-default-filters="false"> 
  <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 
  </context:component-scan> 

 

 

自己总结:spring ioc注入除controller bean。    springmvc只需要注入controller     因为请求进来只会在子容器寻找,在springmvc配置文件加入use-default-filters="false"   意思为只扫面下面配置的,不然会全部扫面,二次实例化

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!