spring容器和SpringMVC容器的区别

2023-05-16

说起spring容器和SpringMVC容器,很多刚接触spring框架的同志都有点懵,甚至是一头雾水,分不清楚两者的关系和区别,包括本人也是,因此还在网上找个不少资料。这俩容器呢虽然有必然的联系,但是他们的区别也是有的。下面我就简单描述下。
首先 springmvc和spring它俩都是容器,容器就是管理对象的地方,例如Tomcat,就是管理servlet对象的,而springMVC容器和spring容器,就是管理bean对象的地方,再说的直白点,springmvc就是管理controller对象的容器,spring就是管理service和dao的容器,这下你明白了吧。所以我们在springmvc的配置文件里配置的扫描路径就是controller的路径,而spring的配置文件里自然配的就是service和dao的路径
SpringMVC.xml文件所配置的路径:

<context:component-scan base-package="com.jd.controller"/>

applicationContext-service.xml文件所配置的路径:

<!--开启注解扫描 扫描dao层和service层-->
<context:component-scan base-package="com.gx.dao,com.jd.service">
    <context:include-filter expression="org.springframework.stereotype.Service" type="annotation"/>
    <context:include-filter expression="org.springframework.stereotype.Repository" type="annotation"/>
</context:component-scan>

其次, spring容器和springmvc容器的关系是父子容器的关系。spring容器是父容器,springmvc是子容器。在子容器里可以访问父容器里的对象,但是在父容器里不可以访问子容器的对象,说的通俗点就是,在controller里可以访问service对象,但是在service里不可以访问controller对象
  所以这么看的话,所有的bean,都是被spring或者springmvc容器管理的,他们可以直接注入。然后springMVC的拦截器也是springmvc容器管理的,所以在springmvc的拦截器里,可以直接注入bean对象。

<!--SpringMVC 拦截器配置(可以多个)--> 
<mvc:interceptors> 
<!--配置拦截器--> 
<mvc:interceptor> 
<!--配置拦截的资源--> 
<mvc:mapping path="/**"/> 
<!--配置拦截器bean对象--> 
<bean class="com.jd.interceptor.MyInterceptor1"/> 
</mvc:interceptor> 
</mvc:interceptors>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

spring容器和SpringMVC容器的区别 的相关文章

随机推荐

  • EF_Using(问题)

    xfeff xfeff using 语句中使用的类型必须可隐式转换为 System IDisposable using 语句中使用的类型必须可隐式转换为 System IDisposable 在使用 EF 出现 using 语句中使用的类型
  • 100个不能错过的实用JS自定义函数

    1 原生JavaScript实现字符串长度截取 代码如下 span class token keyword function span span class token function cutstr span span class tok
  • Android.mk 编译报错undefined reference to

    当出现 undefined reference to xxx时 xff0c 对应的lib库已经添加到LOCAL STATIC LIBRARIES里面 xff0c 且 头文件已经已经添加时 xff0c 仍然报 undefined refere
  • yocto QT5 QSqlDatabase: QSQLITE driver not loaded

    yocto中默认编译出来的qt是不带有sql driver xff0c 即缺少插件库libqsqlite so 修改位置 xff1a 1 在xx meta qt5 recipes qt qt5 qtbase git bb中 xff0c 修改
  • systemd 介绍

    转自 xff1a https www linuxidc com Linux 2018 03 151291 htm 从 init 系统说起 Linux 操作系统的启动首先从 BIOS 开始 xff0c 接下来进入 boot loader xf
  • 详细讲解systemctl(附常用指令)

    目录 写在前面 systemd和systemctl systemd的配置文件目录 主要服务功能类型 服务状态 常用指令 切换系统模式 xff08 文本 界面模式等 xff09 systemctl配置文件的设置 写在前面 我发现systemc
  • Linux中systemctl详细理解及常用命令

    一 systemctl理解 Linux 服务管理两种方式service和systemctl systemd是Linux系统最新的初始化系统 init 作用是提高系统的启动速度 xff0c 尽可能启动较少的进程 xff0c 尽可能更多进程并发
  • ARM AArch64 GUN交叉编译工具下载官网

    Arm Developer https developer arm com tools and software open source software developer tools gnu toolchain gnu a downlo
  • GStreamer系列 - 基本介绍

    什么是Gstreamer xff1f Gstreamer是一个支持Windows xff0c Linux xff0c Android xff0c iOS的跨平台的多媒体框架 xff0c 应用程序可以通过管道 xff08 Pipeline x
  • 探索Android中的Parcel机制(下)

    上一篇中我们透过源码看到了 Parcel 背后的机制 xff0c 本质上把它当成一个 Serialize 就可以了 xff0c 只是它是在内存中完成的序列化和反序列化 xff0c 利用的是连续的内存空间 xff0c 因此会更加高效 我们接下
  • Caused by: java.lang.UnsupportedClassVersionError: Unsupported major.minor version 52.0 (无法载入的.类

    Caused by java lang UnsupportedClassVersionError com iov common crud node TPSAlipayConfig Unsupported major minor versio
  • ubuntu18 buildroot make xconfig make gconfig faile

    make xconfig sudo apt get install qttools5 dev make gconfig sudo apt get install libglade2 dev
  • qt5的configure选项说明

    一 配置选项查看及初步解释 通过下面命令查看都有哪一些编译配置选项 span class token punctuation span span class token operator span configure span class
  • qt build

    QT笔记 嵌入式QT交叉编译与移植 含OpenGL ES2 https blog csdn net weixin 40293570 article details 117731268
  • OpenGL之gult/freeglut/glew/glfw/glad的联系与区别

    转 https blog csdn net libaineu2004 article details 105879521 转 https blog csdn net qq 40565033 article details 107715956
  • linux arm fdisk, 对未使用emmc分区扩容

    yocto编译后的wic镜像 xff0c 在刷机后 xff0c 仍有很大部分emmc未使用 xff0c 下面将未使用的emmc扩展到文件系统挂载分区 root 64 imx8dxmek df h Filesystem Size Used A
  • Shell脚本 EOF使用

    前言 xff1a EOF是End Of File的缩写 xff0c 表示自定义终止符 既然自定义 xff0c 那么EOF就不是固定的 xff0c 可以随意设置别名 xff0c 意思是把内容当作标准输入传给程序 xff0c Linux中按Ct
  • matlab之将视频逐帧保存为图片

    clc clear all close all 将视频逐帧保存为jpg图片 obj 61 VideoReader 39 F mh rgb avi 39 输入视频位置 numFrames 61 obj NumberOfFrames 帧的总数
  • 同步锁

    线程和进程 xff1a 几乎所有的操作系统都支持进程的概念 xff0c 所有运行中的任务通常对应一个进程 xff08 Process xff09 当一个程序 进入内存运行时 xff0c 即变成一个进程 而一个线程中又包含多个进程 多线程的问
  • spring容器和SpringMVC容器的区别

    说起spring容器和SpringMVC容器 xff0c 很多刚接触spring框架的同志都有点懵 xff0c 甚至是一头雾水 xff0c 分不清楚两者的关系和区别 xff0c 包括本人也是 xff0c 因此还在网上找个不少资料 这俩容器呢