首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Spring摘引配置文件方式

2013-08-01 
Spring引用配置文件方式Spring引用配置文件方式1、CLASSPATHcontext:property-placeholder locationclas

Spring引用配置文件方式

Spring引用配置文件方式

1、CLASSPATH

<context:property-placeholder location="classpath:configdir/*.properties"/>

这种就不多讲,一般都这么用!

2、FILE
<context:property-placeholder location="file://${config}/*.properties"/>

在生产环境中,配置文件往往在指定的目录下,而不是在CLASSPATH下面,这种方式这比较好!
${config} 是环境变量,在Eclipse中的Maven Web项目可以这么设置:

打开Maven Build,如下,













这样,启动时候就能根据${config}自动定位到配置文件目录!

注:Main 程序可以通过“Run/Debug Settings”来配置环境变量,过程类似

注:线上生产环境,一般可以在Tomcat等启动的Shell脚本中添加对应环境变量(config=/xxx/xxx

注:Maven打包时,请排除相关config的配置文件,以免将配置文件打进CLASSPATH下面

热点排行