繁体   English   中英

使用属性的JNDI查找来确定弹簧导入

[英]using JNDI lookup of properties to determine spring import

我正在尝试导入属性文件以确定我需要哪个导入。 我查看了以下内容,但他们似乎没有确切的答案:

http://blog.springsource.com/2011/02/15/spring-3-1-m1-unified-property-management/ http://stackoverflow.com/questions/1520055/import-spring-config-file-基于属性文件中的属性

他们很接近,但不完全是我想要的。

<beans:bean id="propertiesResource" class="org.springframework.jndi.JndiObjectFactoryBean"
    p:jndiName="java:comp/env/url/resource/avcs" p:defaultObject="classpath:avcs.properties"/>

<beans:bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <beans:property name="location" ref="propertiesResource"/>
</beans:bean>

<context:property-placeholder properties-ref="propertiesResource" system-properties-mode="ENVIRONMENT"/>

<beans:import resource="applicationContext.${application.context.import}.xml"/>

因此,我需要使用JNDI查找来获取文件,然后加载属性,然后导入特定的应用程序上下文。 如果我仅将属性占位符与类路径资源一起使用,那么我相信一切都会很好,但是在这种情况下,我需要先进行JNDI查找,并且优先顺序似乎将导入放在JNDI之前。

有没有人可以为我解答?

我还有其他想法,但我只是想看看是否有人已经解决了这个问题。

提前致谢。

我相信你将不得不做这样的事情。 我还没有测试过,但基本上PropertyPlaceholderConfigurer中的setLocations方法采用了一个Resource数组(在我们的例子中是UrlResource- http: //static.springsource.org/spring/docs/2.0.x/api/org/springframework/core /io/UrlResource.html ),该文件又具有带有文件路径的构造函数。

<jee:jndi-lookup id="mypropsfile1" jndi-name="myPropsFile1" default-value="file:///C:/defaultPath" resource-ref="true"/>
<jee:jndi-lookup id="mypropsfile2" jndi-name="myPropsFile2" resource-ref="true"/>

<bean id="propertyConfigurer" 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" depends-on="mypropsfile1,mypropsfile2">
  <property name="ignoreUnresolvablePlaceholders" value="true"/>
  <property name="locations">
        <list>
           <bean class="org.springframework.core.io.UrlResource">
               <constructor-arg><ref bean="mypropsfile1"/></constructor-arg>
           </bean>
           <bean class="org.springframework.core.io.UrlResource">
               <constructor-arg><ref bean="myPropsFile2"/></constructor-arg>
           </bean>
        </list>

  </property>
</bean>

在此处检查此讨论。 依赖项将帮助设置特定bean的依赖项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM