Java 注入覆盖应用程序中定义的属性文件的属性文件
我需要一些关于向web应用程序外部定义的bean注入属性值的帮助 web应用程序在src/main/resource下有一个属性文件Java 注入覆盖应用程序中定义的属性文件的属性文件,java,spring,Java,Spring,我需要一些关于向web应用程序外部定义的bean注入属性值的帮助 web应用程序在src/main/resource下有一个属性文件 <context:property-placeholder location="classpath:test.properties,file:/etc/test1.properties" ignore-resource-not-found="true" /> 其中test1.properties是驻留在应用
<context:property-placeholder
location="classpath:test.properties,file:/etc/test1.properties"
ignore-resource-not-found="true"
/>
其中test1.properties是驻留在应用程序外部的另一个文件。bean中注入了应用程序中定义的属性(test.properties),但我想注入test1.properties中定义的属性(理想的想法是覆盖应用程序中的属性值,并读取在应用程序外部定义的属性值)
谢谢。我想这就是你要找的
<context:property-placeholder location="file:c:/kp/sec.properties" order="1" ignore-resource-not-found="true" ignore-unresolvable="true" />
<context:property-placeholder location="classpath:kp-props.properties" order="2" />
Hi在applicationContext.xml中使用如下所示
<util:properties id="property" location="classpath:test.properties"/>
这就是它应该如何工作的,如果不是的话,我怀疑你的文件没有被读取。bean是用组件注释的,包是组件扫描的一部分。因此spring容器加载bean并注入依赖项,但不读取应用程序外部的属性文件值。任何指针都会非常有用。然后它找不到我很确定,当您将
ignore resource not found
设置为false
时,您的应用程序会中断。
<util:properties id="property" location="classpath:test.properties"/>
@Autowired
protected Properties property;