首页 > 编程语言 > 详细

Spring整合SpringMVC

时间:2017-08-10 14:33:10      阅读:352      评论:0      收藏:0      [点我收藏+]
整合:把在springMVC配置文件中的spring提取出来整合为另一份配置文件
希望;
1)、Spring的配置文件只是用来配置和业务逻辑有关的功能(数据源、事务控制、切面....)
2)、SpringMVC的配置文件只是用来配置网站的跳转逻辑、文件上传、国际化这些和web相关功能的;
 

问题: 若 Spring 的 IOC 容器和 SpringMVC 的 IOC 容器扫描的包有重合的部分, 就会导致有的 bean 会被创建 2 次.

解决:

使 Spring 的 IOC 容器扫描的包和 SpringMVC 的 IOC 容器扫描的包没有重合的部分.

使用 exclude-filter 和 include-filter 子节点来规定只能扫描的注解

//springmvc.xml
<context:component-scan base-package="com.atguigu.springmvc" use-default-filters="false">
<context:include-filter type="annotation"
           expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation"
           expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
beans.xml
<context:component-scan base-package="com.atguigu.springmvc">
<context:exclude-filter type="annotation"
        expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation"
        expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
<!-- 配置数据源, 整合其他框架, 事务等. -->

 

 

Spring整合SpringMVC

原文:http://www.cnblogs.com/limingxian537423/p/7339099.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!