尝试在spring中设置外化属性 [英] Trying to setup externalizing properties in spring
问题描述
我正在使用maven构建我的项目,所以根据maven方式,config应该在 src / main / conf
中,我怎么能对我的spring应用程序上下文说那是找到 jdbc.properties
的地方?这是示例bean:
I'm building my project with maven so according to maven way, config should be in src/main/conf
, how can I say to my spring application context that that is where jdbc.properties
is found? Here is example bean :
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="jdbc.properties" />
</bean>
Spring假设这个配置在src / main / webapp / WEB-INF里面,我希望我'已经很清楚,如果不是我会重新解释我的问题谢谢你
Spring assumens that this configuration is inside src/main/webapp/WEB-INF, I hope I've been clear if not I'll rephrase my question thank you
推荐答案
我正在构建我的项目与maven所以
根据maven方式,配置应该
在src / main / conf
I'm building my project with maven so according to maven way, config should be in src/main/conf
实际上,配置数据通常应该放在src / main / resources中,这样它就会在类路径上,你可以引用你的属性文件,如:
Actually, configuration data should generally go in src/main/resources, that way it will be on the classpath and you can reference your property file like:
<property name="location" value="classpath:jdbc.properties" />
这篇关于尝试在spring中设置外化属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!