我有以下spring配置文件:
<context:property-placeholder order="2"
ignore-unresolvable="true" ignore-resource-not-found="true"
location="file:///${user.home}/application.properties" />
<context:property-placeholder order="1"
ignore-unresolvable="true" ignore-resource-not-found="true"
location="file:///C:/Services/Tomcat 6.0/cms/application.properties" />
<context:property-placeholder order="3"
location="classpath:com/afrozaar/cms/service/application.properties" />注意它们是如何排序的,有些在类路径上,有些在文件系统上。
现在,我想添加一个通过jndi加载的属性文件。我希望能做的是
<context:property-placeholder order="2"
ignore-unresolvable="true" ignore-resource-not-found="true"
location="jndi:url/application.properties" />不幸的是,这不起作用,spring不支持jndi前缀...AFAIK。
那么,我能做这样的事情吗?
如果我做不到,我还有什么选择呢?我不想把我的整个配置转换成一个完整的基于bean的属性占位符配置器。
发布于 2013-10-14 23:14:26
不知道"jndi:url/application.properties“到底是什么意思。我想您希望在名为"url/application.properties“的资源条目中设置属性文件的路径。
您可以使用以下代码片段来实现这一点:
<bean class="org.springframework.beans.factory.config.PlaceholderConfigurerSupport">
<property name="location">
<bean id="publisherLocal" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="url/application.properties" />
<property name="expectedType" value="java.lang.String" />
</bean>
</property>
</bean>发布于 2011-07-25 17:24:58
<context:property-placeholder>有一个properties-ref属性,它可以指向Properties类型的bean。因此,您可以在代码中加载Properties并使用它们声明一个<context:property-placeholder>。
https://stackoverflow.com/questions/6813711
复制相似问题