【串线篇】概述SpringMvc和spring整合
SpringMVC和Spring整合的目的;分工明确;
SpringMVC的配置文件就来配置和网站转发逻辑以及网站功能有关的(视图解析器,文件上传解析器,支持ajax,xxx);springmvc.xml
Spring的配置文件来配置和业务有关的(事务控制,数据源,xxx);spring.xml
1. <import resource="spring.xml"/>:可以合并配置文件;虽然是两个spring配置文件,但这种方式仍然相当于一个ioc
2.规范整合
分容器,即两个ioc
1)、在web.xml已经配置SpringMVC的基础上,添加spring容器到web.xml
注意:我们之前配置spring到xml那是一个java项目,并没有web.xml
<!-- needed for ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param> <!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2)、防止两个容器中的组件(只要加注解的组件会被容器创建),被重复创建
SpringMVC.xml与Spring.xml分别加代码
因为Spring管理业务逻辑组件;
排除扫描Controller组件
<context:component-scan base-package="com.atguigu">
<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>
因为SpringMVC管理控制器组件;
只扫描Controller组件 要禁用默认行为
<context:component-scan base-package="com.atguigu" 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>
3)、注意子父容器问题
Spring是一个父容器,SpringMVC是一个子容器;
子容器还可以引用父容器的组件;
父容器不能引用子容器的组件;

注意调用方式,按正常的调用方式即可Controller调Service
【串线篇】概述SpringMvc和spring整合的更多相关文章
- springMVC+MyBatis+Spring 整合(4) ---解决Spring MVC 对AOP不起作用的问题
解决Spring MVC 对AOP不起作用的问题 分类: SpringMVC3x+Spring3x+MyBatis3x myibaits spring J2EE2013-11-21 11:22 640 ...
- Mybatis第五篇【Mybatis与Spring整合】
Mybatis与Spring整合 既然我们已经学了Mybatis的基本开发了,接下来就是Mybatis与Spring的整合了! 以下使用的是Oracle数据库来进行测试 导入jar包 aopallia ...
- 【串线篇】Mybatis之SSM整合
SSM:Spring+SpringMVC+MyBatis 建立Java web项目 一.导包 1).Spring: [aop核心] com.springsource.net.sf.cglib-2.2. ...
- springMVC+mybatis+spring整合案例
1.web.xml a:配置spring监听,使web容器在启动时加载spring的applicationContext.xml <listener> <listener-class ...
- SpringMVC+Mybatis+Spring整合
Maven引入需要的JAR包 pom.xml <properties> <!-- spring版本号 --> <spring.version>4.0.2.RELEA ...
- springMVC+MyBatis+Spring 整合(3)
spring mvc 与mybatis 的整合. 加入配置文件: spring-mybaits.xml <?xml version="1.0" encoding=" ...
- springMVC+MyBatis+Spring 整合(2)
mybatis 与Spring 的整合. 1.导入Spring 和Springmvc的包 pom <project xmlns="http://maven.apache.org/POM ...
- springMVC+Hibernate4+Spring整合一(配置文件部分)
本实例采用springMvc hibernate 与 spring 进行整合, 用springmvc 取代了原先ssh(struts,spring,hibernate)中的struts来扮演view层 ...
- 【串线篇】SpringMVC九大组件
SpringMVC中的Servlet一共有三个层次,分别是HttpServletBean.FrameworkServlet和 DispatcherServlet. HttpServletBean直接继 ...
随机推荐
- Hadoop搭建完全分布式
ubuntu系统下: https://blog.csdn.net/u014636511/article/details/80171002 centos系统下: https://blog.csdn.ne ...
- ORACLE 行转列的通用过程
--测试数据create table rowtocol_test asselect 2009 year,1 month,'部门1' dept,50000 expenditure from dualun ...
- wraps的补充
# import time# def index(name):# '''index函数'''# time.sleep(1)# print('Welcome %s to China'%name)# re ...
- after()和append()的区别、before()和prepend()区别、appendTo()和prependTo()、insertAfter()和insertBefore()
一.after()和before()方法的区别 after()——其方法是将方法里面的参数添加到jquery对象后面去: 如:A.after(B)的意思是将B放到A后面去: before( ...
- cnpm 安装和 command not found
安装cnpm出错 > $ npm install -g cnpm --registry=https://registry.npm.taobao.org 按照淘宝 NPM 镜像安装,cnpm -v ...
- 百度小程序-图片画廊-使用previewImage方法实现
.swan <!-- 轮播图 S--> <view class="swiper-box"> <swiper style='height:{{swipe ...
- 媲美5G的Wifi网速、“备战”资产一键领……揭秘双11小二背后的保障力量
如今,双11不光是购物狂欢节,更是对技术的一次“大考”,对于阿里巴巴企业内部运营的基础保障技术而言,亦是如此. 回溯双11历史,这背后也经历过“小米加步枪”的阶段:作战室从随处是网线,交换机放地上的“ ...
- Ubuntu配置jdk环境变量
下载jdk,解压到你想要的目录 在/etc/profile里最后添加 export JAVA_HOME=/home/zzs0/Programs/jdk1.8.0_102export JRE_HOME= ...
- jmeter添加自定义扩展函数之小写转换大写
1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...
- 使用Gradle打出带签名的apk包
step1:配置build.gradle文件 step1:切换到项目所在目录,用build命令打包 首先 gradle clean 命令清理一下当前项目 E:\AndroidStudioProject ...