2011-07-25 60 views
2

我有以下Spring配置文件:負載JNDI資源的來龍去脈:財產佔位

<context:property-placeholder order="2" 
    ignore-unresolvable="true" ignore-resource-not-found="true" 
    location="file:///${user.home}/application.properties" /> 
<context:property-placeholder order="1" 
    ignore-unresolvable="true" ignore-resource-not-found="true" 
    location="file:///C:/Services/Tomcat 6.0/cms/application.properties" /> 
<context:property-placeholder order="3" 
    location="classpath:com/afrozaar/cms/service/application.properties" /> 

注意他們是如何排序的,有些是在類路徑中,有些是在文件系統上。

現在要混合我想添加通過jndi加載的屬性文件。我希望能夠做到

<context:property-placeholder order="2" 
    ignore-unresolvable="true" ignore-resource-not-found="true" 
    location="jndi:url/application.properties" /> 

不幸的是,這是行不通的,spring不支持jndi前綴...... AFAIK。

那麼,我可以這樣做嗎?

如果我不能取什麼樣的選擇。我不想將我的整個配置轉換爲基於完整bean的屬性佔位符配置器。

回答

0

<context:property-placeholder>有一個properties-ref屬性,它可以指向類型爲Properties的bean。因此,您可以在代碼中加載Properties,並使用它們聲明<context:property-placeholder>

+0

不知道怎麼這會有所幫助... – Wouter

1

不確定你真正的意思是「jndi:url/application.properties」。我想你想在名爲「url/application.properties」的資源項中設置屬性文件的路徑。

您可以用下面的代碼片段實現這一目標:通過使用「JNDI:」

<bean class="org.springframework.beans.factory.config.PlaceholderConfigurerSupport"> 
<property name="location"> 
    <bean id="publisherLocal" class="org.springframework.jndi.JndiObjectFactoryBean"> 
    <property name="jndiName" value="url/application.properties" /> 
    <property name="expectedType" value="java.lang.String" /> 
    </bean> 
</property> 
</bean> 
+0

我希望能夠規避前綴上的資源類似的方式來使用classpath:前綴。 –