Spring应用程序上下文的外部属性? [英] Spring application context external properties?

查看:138
本文介绍了Spring应用程序上下文的外部属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring应用程序,到目前为止它运行良好.现在,我希望属性文件位于外部config文件夹中,而不是在打包的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" />

推荐的一个正在工作,而另一个我却不工作:/有人可以帮忙吗?

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旁边的程序包螺母中,并且在此文件夹中,我需要属性文件.可能吗?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆