---
title: "spring读取properties"
author: "JavaLuSir"
date: "2014-12-08T15:39:32Z"
tags: ["Spring", "properties"]
categories: ["编程语言"]
slug: "spring-properties"
draft: false
lastmod: "2014-12-08T15:39:32Z"
id: 2164195
url: "https://javalusir.iteye.com/blog/2164195"
---

有时候需要把properties文件放在包外方便修改配置。 这里用的是spring的PropertyPlaceholderConfigurer来读取properties属性。 \[code="xml"] file:${user.dir}/config/application.properties file:${user.dir}/config/mailMsg.properties \[/code] 如果用的是eclipse，所以 file:${user.dir} 在windows环境下会取到eclipse路径下，在linux上则会取到你当前放置war包的weblogic的domain下，然后拼接你的路径即可。 也可以用file:${user.home}来获取properties的值，windows的话是document/Users/..的路径，如果是linxu则是根目录下home的路径。 如果你要取包内的properties，用classpath:是取classes下的路径。 这样就能完成war包和配置文件的分离。