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" 意思为只扫面下面配置的,不然会全部扫面,二次实例化
来源:CSDN
作者:进阶的程序猿
链接:https://blog.csdn.net/w962534874/article/details/84582697