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

  1. springMVC+MyBatis+Spring 整合(4) ---解决Spring MVC 对AOP不起作用的问题

    解决Spring MVC 对AOP不起作用的问题 分类: SpringMVC3x+Spring3x+MyBatis3x myibaits spring J2EE2013-11-21 11:22 640 ...

  2. Mybatis第五篇【Mybatis与Spring整合】

    Mybatis与Spring整合 既然我们已经学了Mybatis的基本开发了,接下来就是Mybatis与Spring的整合了! 以下使用的是Oracle数据库来进行测试 导入jar包 aopallia ...

  3. 【串线篇】Mybatis之SSM整合

    SSM:Spring+SpringMVC+MyBatis 建立Java web项目 一.导包 1).Spring: [aop核心] com.springsource.net.sf.cglib-2.2. ...

  4. springMVC+mybatis+spring整合案例

    1.web.xml a:配置spring监听,使web容器在启动时加载spring的applicationContext.xml <listener> <listener-class ...

  5. SpringMVC+Mybatis+Spring整合

    Maven引入需要的JAR包 pom.xml <properties> <!-- spring版本号 --> <spring.version>4.0.2.RELEA ...

  6. springMVC+MyBatis+Spring 整合(3)

    spring mvc 与mybatis 的整合. 加入配置文件: spring-mybaits.xml <?xml version="1.0" encoding=" ...

  7. springMVC+MyBatis+Spring 整合(2)

    mybatis 与Spring 的整合. 1.导入Spring 和Springmvc的包 pom <project xmlns="http://maven.apache.org/POM ...

  8. springMVC+Hibernate4+Spring整合一(配置文件部分)

    本实例采用springMvc hibernate 与 spring 进行整合, 用springmvc 取代了原先ssh(struts,spring,hibernate)中的struts来扮演view层 ...

  9. 【串线篇】SpringMVC九大组件

    SpringMVC中的Servlet一共有三个层次,分别是HttpServletBean.FrameworkServlet和 DispatcherServlet. HttpServletBean直接继 ...

随机推荐

  1. Properties工具类学习

    Properties类学习 1.定义 Properties,java.utils包下的一个工具类,主要用于读取Java的配置文件.各种语言都有自己所支持的配置文件,配置文件中很多变量是经常变动的. 这 ...

  2. 理解Java构造器中的"this"

    Calling Another Constructor if the first statement of a constructor has the form this(...), then the ...

  3. 4412 GPIO读 和 ioremap控制GPIO寄存器

    一.配置GPIO读 在视频14的基础上做 1.利用拨码开关来实现GPIO输入 所以AP_SLEEP对应GPC0_3,然后在drivers/gpio/gpio-exynos4.c中对应EXYNOS4_G ...

  4. 浅谈js for循环输出i为同一值的问题(闭包解决)

    1.最近开发中遇到一个问题,为什么每次输出都是5,而不是点击每个p,就alert出对应的1,2,3,4,5. <html> <head> <meta http-equiv ...

  5. 【HDU5306】【DTOJ2481】Gorgeous Sequence【线段树】

    题目大意:给你一个序列a,你有三个操作,0: x y t将a[x,y]和t取min:1:x y求a[x,y]的最大值:2:x y求a[x,y]的sum 题解:首先很明显就是线段树裸题,那么考虑如何维护 ...

  6. java File类的使用以及一些函数

    package file; import java.io.File; import java.io.IOException; import org.junit.jupiter.api.Test; /* ...

  7. 二叉查找树BST

    每棵子树头节点的值都比各自左子树上所有节点值要大,也都比各自右子树上所有节点值要小. 二叉查找树的中序遍历序列一定是从小到大排列的. 一个节点的后继节点是指,这个节点在中序遍历序列中的下一个节点.相应 ...

  8. paper 155:face/head pose estimation

    参考来源:http://www.cnblogs.com/lanye/p/5312620.html 人脸姿态估计:pitch,yaw,roll三种角度,分别代表上下翻转,左右翻转,平面内旋转的角度.   ...

  9. 处理警告:编码 GBK 的不可映射字符

    怎么处理警告:编码 GBK 的不可映射字符:javac -encoding UTF-8 XX.java使用-encoding参数指明编码方式: 或者 用记事本打开文件,然后另存为,选择ANSI编码,覆 ...

  10. Bugku | Easy_vb

    载入ida,直接搜‘ctf’就有了,坑点是不要交“MCTF{XXX}”,要交“flag{XXXX}”