Spring整合SpringMVC
问题: 若 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的更多相关文章
- spring整合springmvc和hibernate
上篇文章使用maven搭建了web环境,这篇来记录下如何使用spring整合springmvc和hibernate,亦即spring+springmvc+hibernate框架整合. 第一步:首先配置 ...
- spring整合springMVC、mybatis、shiro
jar包: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding& ...
- Spring整合SpringMVC + Mybatis基础框架的配置文件
目录 前言 1. Mybatis层编写 2. Spring层编写 1. Spring整合Mybatis 2. Spring整合service 3. SpringMVC层编写 1. 编写web.xml ...
- 零基础学习java------40---------Maven(maven的概念,安装,maven在eclipse中使用),springboot(spring整合springmvc(注解),spring整合mybatis(常见的配置文件)),前端页面(bootstrap软件)
一 maven 1. Maven的相关概念 1.1 项目开发中遇到的问题 (1)都是同样的代码,为什么在我的机器上可以编译执行,而在他的机器上就不行? (2)为什么在我的机器上可以正常打包,而配置管理 ...
- 阶段3 3.SpringMVC·_07.SSM整合案例_05.ssm整合之Spring整合SpringMVC的框架
点击超连接,执行controller里面的方法 那么就需要在Controller里面定义Service对象,就需要依赖注入进来. 启动tomcat服务器,web.xml里面的前端控制器会帮我加载spr ...
- 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. ...
- spring整合springmvc和mybatis
1.spring 1.1 jar包 1.2 spring基本配置,包扫描注解 <!-- 自动扫描 --> <context:component-scan base-package=& ...
- spring,配置文件applictionContext.xml,Mybatis mybatis.xml,springMVC spring整合springMVC mybatis
- SSM框架整合(Spring、SpringMVC、Mybatis)
#毫无疑问我们肯定是使用Spring去整合SpringMVC和Mybatis,在整合过程中我们首先要让各自的模块实现,然后再去使用Spring整合:比如我先实现Mybatis框架的配置,然后再通过测试 ...
随机推荐
- SqlBulkCopy批量添加
/// <summary> /// 添加数据 /// 注:DataTable列名必须和数据库列名一致 /// </summary> /// <returns>< ...
- Mac中安装JDK1.8和JDK11双版本并任意切换
首先区官网下载JDK8和JDK11安装包,安装后打开bash $ cd /Library/Java/JavaVirtualMachines $ ls -al 可以看到两个版本安装成功 然后编辑环境变量 ...
- AI 数值计算
数值计算,通过迭代来更新解的估计值. 1.上溢和下溢 实数按照一定的精度存储在计算机中,通常存在误差,进而可能导致一些错误. 1)下溢(underflow),例如接近0的数 2)上溢(overflow ...
- C++ 预处理器
直接上代码 1.#define 预处理 #include <iostream> using namespace std; #define PI 3.14159 int main () { ...
- C++的 new 和 detele
什么都不说 直接上代码 哈哈 #include <iostream> using namespace std; int main(int argc, char *argv[]) { co ...
- Git使用—第二讲
前面我们学习了Git最基本的用法,包括安装Git.创建代码仓库,以及提交本地代码.下面我们将学习Git更多的使用技巧,在开始之前,我们先给一个项目创建代码仓库,这里选择在ProviderTest项目中 ...
- 《Google软件测试之道》测试开发工程师
拖延了将近半年的草稿,断断续续的写完了.之前草草翻看完这本书,关注点主要在TE上,而关于SET的部分则只是浏览,最近后知后觉,又翻出了这本书,重新看了一遍,又有新收获. 就说说Google的SET是如 ...
- Kafka 笔记1
Kafka 是对日志文件进行 append 操作,因此磁盘检索的开支是较小的:同时 为了减少磁盘写入的次数,broker 会将消息暂时 buffer 起来,当消息的个数(或大小)达到一定阀值时,再 f ...
- highcharts中数据列点击事件
Highcharts.chart('container', { xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul ...
- [03] mapper.xml的基本元素概述
1.select 我们基于这个持久层接口 GirlDao: public interface GirlDao { List<Girl> findByAge(int age); Girl f ...