Change spring-servlet.xml Filename (Spring Web Contenxt Configuration Filename)

本文介绍如何通过init-param配置Spring的DispatcherServlet,实现更改Spring web应用上下文文件的名称及位置。利用contextConfigLocation参数可以指定多个配置文件的位置,从而灵活地调整Spring MVC应用的初始化配置。

 

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/bean.xml, /WEB-INF/bean-service.xml, 
         /WEB-INF/bean-dao.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

 

Note that in above code snippet, we have passed an init-param to DispatcherServlet called contextConfigLocation. Using this parameter not only can we change the name of Spring’s web context file but also change its location.

This parameter will call setContextConfigLocation method on DispatcherServlet and overrides default context config file. Note that it is possible to add multiple locations separated by any number of commas and spaced.

 

http://viralpatel.net/blogs/change-spring-servlet-filename-configuration/

 

### 关于 Spring Web MVC 5.3.41 的相关信息 Spring Web MVC 是 Spring Framework 中的一个模块,主要用于支持基于 JavaWeb 开发。对于特定版本的信息或依赖下载,可以通过 Maven Central Repository 或其他官方资源获取。 #### 版本信息 Spring Web MVC 作为 Spring Framework 的一部分,在其生命周期中遵循语义化版本控制策略。具体到版本 `5.3.41`,这是属于 Spring Framework 5.x 系列中的一个维护更新版本[^1]。此版本可能包含了若干修复、优化以及兼容性改进。 要了解该版本的具体变更日志,可以访问以下链接查看详细的 Release Notes 和 Changelog: - 官方文档地址:https://spring.io/projects/spring-framework#learn - GitHub 发布页面:https://github.com/spring-projects/spring-framework/releases/tag/v5.3.41 #### 下载方式 通过 Maven 构建工具可以直接引入所需依赖。以下是针对 Spring Web MVC 5.3.41 的 Maven 配置: ```xml <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.41</version> </dependency> ``` 如果使用 Gradle,则配置如下: ```gradle implementation 'org.springframework:spring-webmvc:5.3.41' ``` 这些配置会自动从中央仓库拉取对应的 JAR 文件及其必要的传递依赖项[^2]。 #### 主要功能特性 Spring Web MVC 提供了一套完整的解决方案来简化 Web 应用程序的开发过程。它包括但不限于以下几个方面: - 支持灵活的控制器机制。 - 内置多种视图解析器以适应不同类型的前端技术。 - 自动绑定请求参数至方法参数的功能。 - 对国际化 (i18n) 及主题的支持。 - 易于集成第三方框架如 Thymeleaf、Freemarker 等模板引擎。 此外还提供了诸如向 Session 域或者 Application 域存储数据的能力,这通常用于跨请求间保持状态信息。 #### 示例代码片段 下面展示如何在一个简单的 Controller 类里操作 session 和 application 范围的数据: ```java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.ServletContext; import javax.servlet.http.HttpSession; @Controller public class ScopeController { @RequestMapping("/testSession") public String testSession(HttpSession session){ session.setAttribute("testSessionScope", "hello,session"); return "success"; } @RequestMapping("/testApplication") public String testApplication(HttpSession session){ ServletContext application = session.getServletContext(); application.setAttribute("testApplicationScope", "hello,application"); return "success"; } } ``` 以上代码展示了如何分别设置 session 属性和 application 属性。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值