【问题标题】:Spring PropertyPlaceholderConfigurer not replacing placeholderSpring PropertyPlaceholderConfigurer 不替换占位符
【发布时间】:2011-08-04 09:51:04
【问题描述】:

我想使用 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 - 从 URL [file:D:/bea10.3/user_projects/domains/my_domain/Service.properties] 加载属性文件

因此,尽管 PPC 正在加载 Service.properties 文件,但 ${Service.WSDL.PATH} 似乎没有被替换。

我在这里做错了什么?

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

感谢任何帮助。

【问题讨论】:

  • 尝试:ServletContextPropertyPlaceholderConfigurer -- 但我不知道它有什么不同
  • 您是否遇到了应用程序启动异常,或者该属性没有被替换?

标签: spring weblogic


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2017-01-24
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 2017-09-11
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多