我希望根据属性file.how的请求获取特定值来做到这一点?
我有以下spring配置。我想根据请求设置Exprops的值,并从属性文件中获取相应的值
<bean id="Prop" class="org.springframework.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>
使用PropertiesFactoryBean将Bean中的Properties注入。
<bean id="myPropertiesBean"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="classpath:ErrorMessage.properties"/>
</bean>
这提供了一个Properties对象/ Bean,可以在任何Bean(myPropertiesBean
)中以名称<property name="x" ref="myPropertiesBean"/>
注入。
另外Spring提供了util命名空间(自Spring 2.5开始):你可以将PropertyFactoryBean定义写得更短一些:
<util:properties id="myPropertiesBean"
location="classpath:ErrorMessage.properties"/>
以编程方式执行此操作均使用以下内容
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" />
这返回java.util.Properties对象