spring 容器和spring mvc 容器
来源:5-14 spring、springmvc配置实操

Beliefman_jsy
2018-03-24
老师 我在spring mvc 配置文件和 spring 配置文件 中 我都扫描了 @service注解,那么问题来了, 这个 service实例 是在 spring 两个容器中都有呢,还是在其中一个里面。 还有 就是我再@controller中注入的service 是属于哪个容器的呢?
写回答
1回答
-
Geely
2018-03-24
你好,tongue,这样的话会在spring容器中放两个对象,会有一些问题,这个问题在二期的时候重点领着大家来修复来着。controller里注入的这个就要看加载顺序了,我们在springmvc里应该是这么写,通过exclude来把其他包排除,只保留controller包。
在spring里面是这么写,把controller注解排除。
<!-- 二期温馨提示,springmvc扫描包指定到controller,防止重复扫描 -->
<context:component-scan base-package="com.mmall.controller" annotation-config="true" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
00
相似问题