我在spring applicationContext.xml
中有以下配置<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<context:property-placeholder location="file:///absolute/path/to/foo.properties"/>
<context:property-placeholder location="file:///absolute/path/to/bar.properties"/>
<util:properties id="baz" location="file:///absolute/path/to/bar.properties"/>
我可以将调试断点放在加载属性文件的位置,并查看属性文件的值确实已加载。
但在我的bean中,@Value("#{baz.myProp}")
已解决,而@Value("${myProp}")
在PropertyPlaceholderHelper
中爆炸,因为PropertySourcesPropertyResolver
无法找到myProp
:
DEBUG [...] - Searching for key 'myProp' in [environmentProperties]
DEBUG [...] - Searching for key 'myProp' in [systemProperties]
DEBUG [...] - Searching for key 'myProp' in [systemEnvironment]
DEBUG [...] - Could not find key 'myProp' in any property source. Returning [null]
DEBUG [...] - Searching for key 'myProp' in [localProperties]
DEBUG [...] - Could not find key 'myProp' in any property source. Returning [null]
为什么会这样,如何使其工作(使用$
属性占位符解析而不是#
SpEL语法?)
通过context:property-placeholder
加载的属性是否被util:properties
丢弃/覆盖(只能通过baz
引用访问)?
答案 0 :(得分:0)
Turns out这就是每个context:property-placeholder
行所需的全部内容,让每个人都有机会参与解析该属性:ignore-unresolvable="true"
...