内容简介:Spring Web项目spring配置文件随服务器启动时自动加载
前言:其实配置文件不随服务器启动时加载也是可以的,但是这样操作的话,每次获取相应对象,就会去读取一次配置文件,从而降低程序的效率,而Spring中已经为我们提供了监听器,可监听服务器是否启动,然后在启动时,加载spring的配置文件,并且只加载一次,从而提高程序效率。
实现:其配置需要在web.xml中进行,具体实现如下:
<!--配置监听器 --> <!--以便在服务器启动的时候,加载spring配置文件-->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!--配置spring配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-context.xml</param-value>
</context-param>
注:这里注意<context-param>标签中<param-name>中的内容为固定值,<param-value>中内容为固定格式:classpath:spring配置文件(如有路径请加上)
通过以上配置就可以让spring配置文件随服务器启动而加载了。
本文永久更新链接地址 : http://www.linuxidc.com/Linux/2018-01/150263.htm
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- SpringBoot配置加载顺序
- golang 加载ini风格配置文件
- 「快学SpringBoot」配置文件的加载顺序和配置项默认值设置
- web.xml的加载过程配置详解
- Laravel Config—— 配置文件的加载与源码解析
- 在运行时热加载Prometheus的配置信息
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Big Java Late Objects
Horstmann, Cay S. / 2012-2 / 896.00元
The introductory programming course is difficult. Many students fail to succeed or have trouble in the course because they don't understand the material and do not practice programming sufficiently. ......一起来看看 《Big Java Late Objects》 这本书的介绍吧!
UNIX 时间戳转换
UNIX 时间戳转换
HSV CMYK 转换工具
HSV CMYK互换工具