[英]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.