相关疑难解决方法(0)

根据配置文件在Spring中加载属性文件

我有一个Spring 3.1应用程序。假设它具有包含以下内容的XML:

<context:property-placeholder location="classpath:somename.properties" />

<context:property-placeholder location="classpath:xxx.properties" />
Run Code Online (Sandbox Code Playgroud)

我希望始终加载some.properties(假设它存在),但是第二个占位符的xxx部分将根据活动的配置文件用某些名称替换。我已经试过了:

<beans profile="xx1">
    <context:property-placeholder location="classpath:xx1.properties" />
</beans>

<beans profile="xx2">
    <context:property-placeholder location="classpath:xx2.properties" />
</beans>
Run Code Online (Sandbox Code Playgroud)

此外,两个文件的属性均具有相同的键,但值不同。

但是它没有用,因为某些后来的Bean具有一个属性的占位符,该属性的键在xx1.properties(和xx2.properties)中定义,因此Spring抱怨说在应用程序上下文中找不到该键。

java spring

4
推荐指数
1
解决办法
9440
查看次数

标签 统计

java ×1

spring ×1