0
這不是工作:如何通過春季表達式語言評估作爲一個參數?
<?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:encryption="http://www.jasypt.org/schema/encryption"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.jasypt.org/schema/encryption
http://www.jasypt.org/schema/encryption/jasypt-spring31-encryption-1.xsd">
<import resource="properties/secure/jasypt-context.xml" />
<bean name="propEnvironment" class="java.lang.String">
<constructor-arg value="#{ systemProperties['property.environment'] ?: systemProperties['cfg.environment'] }" />
</bean>
<encryption:encryptable-property-placeholder
encryptor="configurationEncryptor"
location="classpath:properties/#{propEnvironment}/*.properties,classpath:properties/common.properties" />
</beans>
只有common.properties得到由可加密屬性佔位符配置。這就像其他條目剛剛消失(沒有錯誤或任何東西,它只是不加載任何其他)。我想站在生產配置文件的實例上,但我想使用我的開發屬性。如果我打印出來,拼寫表達式正在評估。這可能嗎?
當我嘗試這一點,
<bean name="propEnvironment" class="java.lang.String" id="testing">
<constructor-arg value="#{ systemProperties['property.environment'] ?: systemProperties['cfg.environment'] }" />
</bean>
<bean name="fullString" class="java.lang.String">
<constructor-arg value="classpath:properties/#{ systemProperties['property.environment'] ?: systemProperties['cfg.environment'] }/*.properties" />
</bean>
<bean class="EchoBean" lazy-init="false">
<constructor-arg ref="propEnvironment" />
</bean>
<bean class="EchoBean" lazy-init="false">
<constructor-arg ref="fullString" />
</bean>
<bean class="EchoBean" lazy-init="false">
<constructor-arg value="#{@testing.toString()}" />
</bean>
<bean class="EchoBean" lazy-init="false">
<constructor-arg value="blah" />
</bean>
使用@語法不產生任何輸出第三回聲。
2014-02-14 10:03:41,998 [main] INFO EchoBean - local
2014-02-14 10:03:42,000 [main] INFO EchoBean - classpath:properties/local/*.properties
2014-02-14 10:03:42,000 [main] INFO EchoBean - blah
我不知道。看起來Spring想要在評估spring-el之前構建屬性佔位符 –
@Mongo - 發佈了一個更新的示例以供嘗試,希望它有所幫助。如果這不起作用,你可以嘗試自動裝配'propEnvironment'字符串bean到一些組件,並看看值是否正確? – SergeyB
'@'語法似乎不適合我。 –