开发者

Reading valued from properties file at Runtime

I want to get specific value based on request from the property file.how to do that?

I have following spring configuration.i want to set the value for Exprops as per the request and get corresponding values from the properties file

<bean id="Prop" class="org.springfram开发者_JS百科ework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>classpath:ErrorMessage.properties</value>
    </property>
</bean>

<bean id="PropertiesBean" class="com.util.PropertiesUtil">
    <property name="Exprops" value="${EXampleExceptiion}"></property>
</bean>


Use the PropertiesFactoryBean to inject the Properties in a Bean.

<bean id="myPropertiesBean"
  class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="location" value="classpath:ErrorMessage.properties"/>
</bean>

This provides a Properties Object/Bean which can be injected under the name myPropertiesBean in any Bean (<property name="x" ref="myPropertiesBean"/>).

In addition Spring provides the util namespace (since Spring 2.5): There you can write the PropertyFactoryBean definition a bit shorter:

<util:properties id="myPropertiesBean"
 location="classpath:ErrorMessage.properties"/>

@see Spring Reference Chapter C.2.2.3.


All use the following for doing this programmatically

XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource("beans.xml"));
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
cfg.setLocation(new FileSystemResource("jdbc.properties"));
cfg.postProcessBeanFactory(factory);


<util:properties id="" location="location of prop file" />

this return java.util.Properties object

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜