七、SpringWeb-Spring快速入门小白编

思路:启动tomcat时,自动加载applicationContext.xml配置文件

启动tomcat会自动加载web.xml

所以在web.xml中进行配置,加入监听器即可

<!--    定义ioc容器所在位置-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
<!--    配置spring-web.jar包提供的监听器,以便在服务器启动是初始化ioc容器-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

注:如果applicationContext.xml配置文件在web-inf目录下,可以不使用 <context-param>定义ioc容器位置

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一. Java基础部分.................................................
    wy_sure阅读 9,262评论 0 11
  • 1.Spring整体架构 1)核心容器(Core Container) Core模块,主要包含了Spring框架基...
    Sponge1128阅读 4,849评论 0 1
  • 本文从API角度入手,带你了解SpringMVC启动的原理。 ServletContainerInitialize...
    南桥畂翊阅读 11,162评论 1 14
  • 一、 Spring技术概述1、什么是Spring : Spring是分层的JavaSE/EE full-stack...
    luweicheng24阅读 4,012评论 0 1
  • 本文转载自:关于web.xml配置的那些事儿 - 个人文章 - SegmentFault 思否 1.简介 web....
    PinenutPan阅读 5,958评论 0 5