`

在web.xml中通过contextConfigLocation配置spring

阅读更多

部署到tomcat后,src目录下的配置文件会和class文件一样,自动copy到应用的 classes目录下

spring的 配置文件在启动时,加载的是web-info目录下的applicationContext.xml,
运行时使用的是web-info/classes目录下的applicationContext.xml。

配置web.xml使这2个路径一致:

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
 </context-param>

多个配置文件的加载
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath*:conf/spring/applicationContext_core*.xml,
            classpath*:conf/spring/applicationContext_dict*.xml,
            classpath*:conf/spring/applicationContext_hibernate.xml,
            classpath*:conf/spring/applicationContext_staff*.xml,
            classpath*:conf/spring/applicationContext_security.xml
            classpath*:conf/spring/applicationContext_modules*.xml
            classpath*:conf/spring/applicationContext_cti*.xml
            classpath*:conf/spring/applicationContext_apm*.xml
        </param-value>
    </context-param>

contextConfigLocation 参数定义了要装入的 Spring 配置文件。

分享到:
评论

相关推荐

    spring在web.xml中和在struts中的不同配置..pdf

    在本文中,我们将探讨Spring在`web.xml`中的配置与在Struts中的配置差异,以及这两种配置方式背后的基本原理。 首先,Spring的核心是ApplicationContext,它是一个管理Bean的容器,可以看作是应用程序的上下文环境...

    加载spring 文件,在web.xml中的配置

    在Spring框架中,Web应用程序的配置通常涉及到对`web.xml`文件的设置,这是传统的部署描述符,用于定义Servlet、监听器和其他Web组件。当我们谈论“加载Spring文件,在web.xml中的配置”时,主要是指如何在Web应用...

    web.xml文件中配置(servlet, spring, filter, listenr)的加载顺序

    在`web.xml`中配置Spring时,通常通过Listener来加载Spring容器,这样可以在应用程序启动时初始化所有的Spring Bean。 **示例代码:** ```xml org.springframework.web.context.ContextLoaderListener ...

    web.xml中如何设置配置文件的加载路径实例详解

    web应用程序通过Tomcat等容器启动时,会首先加载web.xml文件,通常我们工程中的各种配置文件,如日志、数据库、spring的文件等都在此时被加载,下面是两种常用的配置文件加载路径,即配置文件可以放到 SRC目录下或者...

    Spring在web.xml中的配置详细介绍

    在Java Web应用中,Spring框架的使用已经非常普遍,而web.xml是Java EE标准的web应用配置文件,它用于配置web应用的各种属性。要将Spring框架与web.xml结合使用,需要进行一些特定的配置,从而使得Spring能够管理web...

    spring在web.xml中和在struts中的不同配置.[收集].pdf

    本篇文章将深入探讨Spring在`web.xml`中与在Struts中的不同配置方式,以及这两种方式背后的设计思想。 首先,ApplicationContext是Spring的核心组件,它是一个容器,负责管理和装配应用程序中的Bean。在Web应用中,...

    SSH和SSI等框架常用基础配置web.xml

    在Java Web应用开发中,`web.xml`是部署描述符的核心部分,用于定义与Web应用程序相关的配置信息。对于使用SSH(Struts + Spring + Hibernate)和SSI(Struts + Spring + iBatis)等框架的应用程序而言,合理的`web....

    springmvc、spring、mybatis的resources配置文件和web.xml

    在Spring的资源配置文件(通常命名为`beans.xml`)中,我们可以定义Bean的实例化、初始化方法、属性注入等。例如: ```xml &lt;bean id="exampleService" class="com.example.ExampleService"&gt; ``` 这里创建了...

    web.xml配置解析[总结].pdf

    通过在`web.xml`中配置如下: ```xml &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener ``` 当Servlet容器启动时,`ContextLoaderListener`会查找`ApplicationContext`的配置...

    web.xml配置解析.pdf

    当web.xml中配置了`&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;`,容器启动时会调用其相关方法,初始化Spring应用上下文。ContextLoaderListener依赖于ContextLoader...

    web.xml中的listen

    ### Web.xml中的Listen知识点详解 ...通过上述分析可以看出,`web.xml`中的监听器不仅可以帮助我们加载Spring配置文件,还可以实现更灵活的功能,如监听自定义Java类等。这对于扩展Web应用的功能非常有用。

    开发web_xml.rar_WEB XML_java web开发_web.xml_web开发_web

    在Java Web开发中,`web.xml`文件是部署描述符(Deployment Descriptor)的核心部分,它在应用程序中扮演着至关重要的角色。`web.xml`文件是一个XML格式的配置文件,用于定义Servlet、过滤器(Filter)、监听器...

    JAVA web.xml配置详解

    &lt;param-value&gt;/WEB-INF/spring-config.xml &lt;!-- 备注:此所设定的参数,在JSP网页中可以使用下列方法来取得:${initParam.param_name} 若在Servlet可以使用下列方法来获得:String param_name=getServletContext...

    spring web.xml指定配置文件过程解析

    通过配置web.xml文件,我们可以轻松地配置Spring Web应用程序的核心组件,从而快速搭建Web应用程序。 ContextLoaderListener ContextLoaderListener 是 Spring 框架中的一个核心组件,它负责读取上下文配置文件,...

    web.xml配置[归纳].pdf

    《web.xml配置归纳》 ...总结来说,`web.xml`是Java Web应用的灵魂,通过精确配置,我们可以控制Spring的上下文加载、过滤器的执行、MVC框架的行为、日志系统的初始化以及Ajax框架的功能,实现高效且定制化的Web应用。

    spring MVC配置详解

    在 web.xml 文件中配置 ContextLoaderListener 和 contextConfigLocation,以便加载 Spring 的配置文件。 ```xml &lt;!-- Spring 配置 --&gt; org.springframework.web.context.ContextLoaderListener ...

    spring在web.xml中和在struts中的不同配置

    Spring 在 web.xml 中和在 Struts 中的不同配置 在本文中,我们将探讨 Spring 在 web.xml 中和在 Struts 中的不同配置。首先,我们需要了解 Spring 的核心概念之一:ApplicationContext。 ApplicationContext 是 ...

    ssh框架在application.xml中配置数据源所需jar

    - dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation"). --&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...

    ssm框架下web项目,web.xml配置文件的作用(详解)

    在web.xml文件中,我们还需要配置DispatcherServlet,以便将所有的请求交给Spring MVC处理。DispatcherServlet是一个Servlet,它负责将请求分配给不同的Controller,以便进行处理。 ```xml &lt;servlet-name&gt;mvc-...

Global site tag (gtag.js) - Google Analytics