Spring应用程序上下文外部属性? [英] Spring application context external properties?
问题描述
我有一个 Spring 应用程序,到目前为止它运行良好.现在我希望在外部配置文件夹中而不是在打包的 jar 中的属性文件可以更改内容而无需重新打包.这是我得到的:
i have a Spring application and its working well so far. Now i want the properties file in an external config folder and not in the packed jar to change things without the need to repack. This is what i got:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<!-- <property name="locations" value="classpath:/springcontext.properties"/> -->
<property name="locations" value ="config/springcontext.properties" />
outcommented 一个正在工作,另一个我没有上班:/有人可以帮忙吗?
The outcommented one is working and the other one i dont get to work :/ Can someone help?
到目前为止,已有 4 条评论.
Thx 4 comments so far.
也许我的问题不够清楚:).我执行 Maven 构建,所有内容都将被打包,我希望这个文件夹不在输出 jar 旁边的包 nut 中,在这个文件夹中我想要属性文件.可能吗?
Maybe my question wasnt clear enough :). I perform a Maven build and everything will be packaged and i want this folder to be NOT in the package nut next to the outcomming jar and in this folder i want the properties file. possible?
推荐答案
<context:property-placeholder location="classpath*:spring/*.properties" />
如果你把它放在名为 spring 的目录中的类路径中的某个位置(相应地更改名称/目录),你可以访问上面
If you place it somewhere in the classpath in a directory named spring (change names/dirs accordingly), you can access with above
<property name="locations" value ="config/springcontext.properties" />
这将指向 web-inf/classes/config/springcontext.properties
this will be pointing to web-inf/classes/config/springcontext.properties
这篇关于Spring应用程序上下文外部属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!