我想使用 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
我的 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]
因此,尽管 Service.properties 文件被 PPC 加载,但 ${Service.WSDL.PATH}
似乎没有被替换。
我在这里做错了什么?
另外,我如何才能知道 PPC 是否尝试用什么值替换占位符的值?我希望日志文件会包含该信息,但那里什么也没有。
感谢任何帮助。
最佳答案
我发现,PropertyPlaceholderConfigurer 需要首先在应用程序上下文文件中声明,否则无法保证加载顺序。我花了几个小时才意识到这一点。
尝试将“file.path”bean 移动到 PropertyPlaceHolderConfigurer 的位置属性中。
关于Spring PropertyPlaceholderConfigurer 不替换占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6939305/