整合:把在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的更多相关文章

  1. spring整合springmvc和hibernate

    上篇文章使用maven搭建了web环境,这篇来记录下如何使用spring整合springmvc和hibernate,亦即spring+springmvc+hibernate框架整合. 第一步:首先配置 ...

  2. spring整合springMVC、mybatis、shiro

    jar包: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding& ...

  3. Spring整合SpringMVC + Mybatis基础框架的配置文件

    目录 前言 1. Mybatis层编写 2. Spring层编写 1. Spring整合Mybatis 2. Spring整合service 3. SpringMVC层编写 1. 编写web.xml ...

  4. 零基础学习java------40---------Maven(maven的概念,安装,maven在eclipse中使用),springboot(spring整合springmvc(注解),spring整合mybatis(常见的配置文件)),前端页面(bootstrap软件)

    一 maven 1. Maven的相关概念 1.1 项目开发中遇到的问题 (1)都是同样的代码,为什么在我的机器上可以编译执行,而在他的机器上就不行? (2)为什么在我的机器上可以正常打包,而配置管理 ...

  5. 阶段3 3.SpringMVC·_07.SSM整合案例_05.ssm整合之Spring整合SpringMVC的框架

    点击超连接,执行controller里面的方法 那么就需要在Controller里面定义Service对象,就需要依赖注入进来. 启动tomcat服务器,web.xml里面的前端控制器会帮我加载spr ...

  6. spring整合springMVC、mybatis、hibernate、mongodb框架

    开发环境 eclipse Mars 4.5 JDK 1.7 框架 spring 4.0.5 mybatis 3.2.7 hibernate 4.3.6 mongodb 1.7 数据库 MySQL 5. ...

  7. spring整合springmvc和mybatis

    1.spring 1.1 jar包 1.2 spring基本配置,包扫描注解 <!-- 自动扫描 --> <context:component-scan base-package=& ...

  8. spring,配置文件applictionContext.xml,Mybatis mybatis.xml,springMVC spring整合springMVC mybatis

  9. SSM框架整合(Spring、SpringMVC、Mybatis)

    #毫无疑问我们肯定是使用Spring去整合SpringMVC和Mybatis,在整合过程中我们首先要让各自的模块实现,然后再去使用Spring整合:比如我先实现Mybatis框架的配置,然后再通过测试 ...

随机推荐

  1. VS Code 快捷键使用小技巧

    相关文档 官方文档(英文版):Documentation for Visual Studio Code 中文文档(未完成):GitHub - jeasonstudio/CN-VScode-Docs: ...

  2. vue项目的架构设计完善详解

    vue项目构建vuex+mock层 vue项目添加jsBridge(与原生交互的) vue项目添加代码格式化

  3. 元素的组合(dfs)

    无重复元素的组合 输入一串小些字母(无重复字母),从中取出k(k<10)个字母,输出组合情况.样例:输入:abcd3输出:abcabdacdbcd 一道搜索的题,想办法建图或是画搜索树. 这里推 ...

  4. Qt5.7 + VS2015 环境搭建

    http://blog.csdn.net/liang19890820/article/details/53931813#安装插件 配置 Qt 5.7 选择:Qt VS Tools -> Qt O ...

  5. ethereum/EIPs-1077 Executable Signed Messages

    https://github.com/alexvandesande/EIPs/blob/ee2347027e94b93708939f2e448447d030ca2d76/EIPS/eip-1077.m ...

  6. C++反转单链表

    单链表 /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } }; ...

  7. protobuf可变长编码的实现原理

    protobuf中的整数,如int32.int64.uint32.uint64.sint32.sint64.bool和enum,采用可变长编码,即varints. 这样做的好处是,可以节省空间.根据整 ...

  8. Luogu P1082 同余方程(exgcd模版)

    传送门 求ax%b = 1,即ax - by = 1: 很明显这是一个exgcd的形式. 那么要做这道题,首先需要gcd和exgcd的算法作铺垫. gcd(辗转相膜法): int gcd(int a, ...

  9. 洛谷 P2256 一中校运会之百米跑

    题目链接 https://www.luogu.org/problemnew/show/P2256 题目背景 在一大堆秀恩爱的**之中,来不及秀恩爱的苏大学神踏着坚定(?)的步伐走向了100米跑的起点. ...

  10. TCP/IP协议--TCP的超时和重传

    TCP是可靠传输.可靠之一体现在收到数据后,返回去一个确认.但是不能完全避免的是,数据和确认都可能丢失.解决这个办法就是,提供一个发送的重传定时器:如果定时器溢出时还没收到确认,它就重传这个报文段. ...