在 PropertyPlaceholderConfigurer 实例中使用
2024-03-16


环境:Windows Server 2003、Spring 3.0、Tomcat 6

如何在 PropertyPlaceholderConfigurer 中引用 JNDI 属性?

具体来说,我使用 JNDI 来查找表示路径的 java.lang.String 我的网络应用程序需要的属性文件

<jee:jndi-lookup id="mypropsfile1" jndi-name="myPropsFile1" resource-ref="true"/>
<jee:jndi-lookup id="mypropsfile2" jndi-name="myPropsFile2" resource-ref="true"/>

<bean id="propertyConfigurer" 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="ignoreUnresolvablePlaceholders" value="true"/>
  <property name="locations">
    <array>
        <value>how to use mypropsfile1 here ??</value>
        <value>how to use mypropsfile2 here ??</value>
    </array>
  </property>
</bean>

我的“jee:jndi-lookup”正在工作。我的问题似乎是如何引用 JNDI 资源 在标签对内

提前致谢! 标记


你的方法可能不起作用,马克,这是因为 PropertyPlaceHolderConfigurer 是一个 BeanFactoryPostProcessor,并且在创建 bean 定义时被调用,而 jndi 查找发生在这个阶段之后。

我看到一个老Spring论坛 http://forum.springsource.org/showthread.php?14361-PropertyPlaceholderConfigurer-search-in-JNDI讨论项,其中推荐了一种使用基于 jndi 查找的属性文件的方法,这可能适合您的需求:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 PropertyPlaceholderConfigurer 实例中使用

随机推荐