[英]Spring expression in xml configuration file
为不同的用户提供不同的属性集很有用。
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder
location="classpath:/path/to/package/default.properties,
classpath:/path/to/package/#{ systemProperties['user.name'] }.properties"/>
</beans>
执行应用程序时,spring无法识别表达式。 上下文没有启动,spring说: class path resource [path/to/package/#{ systemProperties['user.name'] }.properties] cannot be opened
当我用字符串手动替换表达式导致有效资源时,行为是预期的。 手册说它应该工作。
spring-context和spring-core(3.1.2-RELEASE)在classpath中。
那里不允许使用SpEL表达式; 你可以间接做你想做的事,但......
<context:property-placeholder properties-ref="props"/>
<util:properties id="props" location="classpath:#{systemProperties['foo']}"/>
这是问题的完整答案。 保持用户属性覆盖默认属性。 我对已接受答案的编辑遭到拒绝。
<context:property-placeholder properties-ref="springContextCongifurationProperties"
location="classpath:/path/to/package/default.properties"
local-override="true"/>
<util:properties id="springContextCongifurationProperties"
location="classpath:/path/to/package/#{ systemProperties['user.name'] }.properties"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.