`

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下面
  • 大小: 35.2 KB
  • 大小: 25.2 KB
  • 大小: 27.6 KB
  • 大小: 26.2 KB
  • 大小: 50.6 KB
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics