我正在尝试从类路径加载属性文件值以在属性占位符配置器位置属性中解析,这个想法是我可以根据从类路径文件加载的值加载外部属性文件。 ..一个例子可能会让这更容易理解......
1)从类路径加载一些属性
<bean id="globalProperties" class="common.config.ServletContextPropertyPlaceholderConfigurer">
<property name="key" value="globalProperties" />
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>classpath:application.properties</value>
</list>
</property>
</bean>
2)现在想在下一个占位符配置器中使用上面加载的属性:
<bean id="appProperties" class="common.config.ServletContextPropertyPlaceholderConfigurer">
<property name="key" value="appProperties" />
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>file:#{globalProperties['app.config']}/app.config.properties</value>
<value>file:${user.home}/app.config.properties</value>
<value>file:${user.dir}/app.config.properties</value>
</list>
</property>
</bean>
如果我尝试使用$ {}语法加载它,那么这就是用于加载文件的内容,显然永远不会加载,例如${app.config}/app.config.properties
(由于变量未被转换,因此无法找到类) 。系统变量${user.home}
确实正确转换,那么如何在另一个属性占位符配置器中使用我作为值加载的属性?这可能吗?
尝试使用我的示例文件中的代码:
#{globalProperties['app.config']}/app.config.properties
给出一个弹簧错误:
Error creating bean with name 'appProperties' defined in ServletContext resource [/WEB-INF/config/properties.xml]:
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed;
nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1027E:(pos 16): Indexing into type 'common.config.ServletContextPropertyPlaceholderConfigurer' is not supported