2011-08-04 85 views
3

我想使用PropertyPlaceHolderConfigurer動態地將內部Web服務的WSDL URL傳遞到Spring beans.xml中。Spring PropertyPlaceholderConfigurer不替換佔位符

這裏是場景:

我的web應用程序部署在WebLogic 10.3中。 WSDL url包含在屬性文件之外我的應用程序(直接位於相應的域文件夾下,而我的應用程序位於自動部署文件夾內)。我設置該屬性的位置在我的域名的文件的setDomainEnv.cmd文件象下面這樣:

set JAVA_PROPERTIES=%JAVA_PROPERTIES% %CLUSTER_PROPERTIES% -Dproperty.file.path.config=%DOMAIN_HOME%\Service.properties 

這是我的Service.properties文件包含:

Service.WSDL.PATH=http://localhost:8088/mockServiceSoap?WSDL 

我的春天的beans.xml配置:----

<bean id="file.path" class="java.lang.System" factory-method="getProperty"> 
     <constructor-arg index="0"><value>property.file.path.config</value></constructor-arg> 
</bean> 

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="location" ref="file.path"/> 
</bean> 

<bean id="myServiceId" class="com.test.service.ServiceImpl"> 
    <property name="myServiceSoap"> 
    <ref bean="myService"/> 
    </property> 
</bean> 

<bean id="myService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean"> 
    <property name="serviceInterface" value="com.test.service.ServiceSoap"/> 
    <property name="wsdlDocumentUrl" value="${Service.WSDL.PATH}"/> 
</bean> 

我啓用了調試日誌專門爲PPC,這是我在我的應用程序日誌中看到:

 
INFO org.springframework.beans.factory.config.PropertyPlaceholderConfigurer 178 - Loading properties file from URL [file:D:/bea10.3/user_projects/domains/my_domain/Service.properties] 

因此,雖然Service.properties文件正在通過PPC加載,但${Service.WSDL.PATH}未被替換。

我在這裏做錯了什麼?

另外,我怎麼知道PPC是否試圖替換佔位符的值以及什麼值?我希望日誌文件包含該信息,但沒有任何內容。

任何幫助表示讚賞。

+0

嘗試:ServletContextPropertyPlaceholderConfigurer - 但我不知道它是否有所作爲 – Ralph

+0

您是否遇到應用程序啓動異常,或者屬性沒有被替換? – Ralph

回答

2

我已經想通了,PropertyPlaceholderConfigurer需要首先在應用程序上下文文件中聲明,否則不能保證加載順序。我花了幾個小時才意識到這一點。

嘗試將「file.path」bean移動到PropertyPlaceHolderConfigurer的location屬性中。