Spring PropertyPlaceholderConfigurer不替换占位符

时间:2011-08-04 09:51:04

标签: spring weblogic

我想使用PropertyPlaceHolderConfigurer动态地将内部Web服务的WSDL URL传递到我的Spring beans.xml中。

以下是该方案:

我的Web应用程序部署在WebLogic 10.3中。 WSDL URL包含在位于外部我的应用程序的属性文件中(直接位于相应的域文件夹下,而我的应用程序位于 autodeploy 文件夹中)。我在我的域的 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

My Spring 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启用了DEBUG日志,这是我在应用程序日志中看到的:

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

因此,虽然PPC正在加载Service.properties文件,但${Service.WSDL.PATH}并未被替换。

我在这里做错了什么?

另外,如何判断PPC是否尝试替换占位符的值以及具有什么值?我希望日志文件包含该信息,但那里什么都没有。

感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

我已经发现,需要在应用程序上下文文件中首先声明PropertyPlaceholderConfigurer,否则无法保证加载顺序。我花了几个小时才意识到这一点。

尝试将“file.path”bean移动到PropertyPlaceHolderConfigurer的location属性中。

相关问题