开发者

Load jndi resources into context:property-placeholder

I have the following spring config file:

<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" />

Notice how they are ordered, some are on the classpath and some are on the file system.

Now to the mix I want to add a properties file loaded via jndi. I was hoping to be able to do

<context:property-placeholder order="2"
    ignore-unresolvable="true" ignore-resource-not-found="true"
    location="jndi:url/application.properties" />

Unfortunately, this doesn'开发者_开发知识库t work, spring doesn't support the jndi prefix... AFAIK.

So, can I do something like this?

And if I can't what's my alternative. I don't want to have to convert my whole configuration to a full bean based property place holder configurer.


Not sure what you really mean with "jndi:url/application.properties". I suppose you wanted to set the path to the property file in a resource entry named "url/application.properties".

You can achieve this with the following snippets:

<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>


<context:property-placeholder> has a properties-ref attribute, which can point to the bean of type Properties. So, you can load Properties in your code and declare a <context:property-placeholder> using them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜