Spring 如何读取properties文件
------解决方案--------------------------------------------------------
BeanDefinitionRegistry reg = new DefaultListableBeanFactory();
PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(reg);
reader.loadBeanDefinitions(new ClassPathResource("beanConfig.properties"));
BeanFactory factory = (BeanFactory)reg;
或者
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>src/jdbc.properties</value>
</property>
</bean>
Spring - 资源文件properties的配置
Spring简化了加载资源文件的配置,可以通过<context:property-placeholder去加载,这个元素的写法如下:
<context:property-placeholder location="classpath:jdbc.properties"/>
如果想要配置多个properties文件
<context:property-placeholder location="classpath:jdbc.properties"/>
<context:property-placeholder location="classpath:jdbc.properties"/>
这种方式是不被允许的,一定会出"Could not resolve placeholder"。
解决方案:
(1) 在Spring 3.0中,可以写:
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>
(2) 但是在Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,所以就不能使用上面的那种方法去配置,
可以改如下的格式:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/jdbc.properties</value>
</list>
</property>
</bean>
分享到:
相关推荐
Spring 读取properties文件key+value方式.rar
spring读取properties.
spring读取properties配置文件的key值。
主要介绍了spring无法读取properties文件数据问题详解,需要的朋友可以参考下
主要介绍了Spring用代码来读取properties文件实例解析,具有一定借鉴价值,需要的朋友可以参考下
之前的系统用的是Spring框架,国际化还是比较简单的。但是有一些提示是写在js文件里面的,搜了一些,发现一个js国际化的框架jquery.i18n.properties.js,用了一些还是比较方便的。
NULL 博文链接:https://nannan408.iteye.com/blog/2256177
1、在maven工程导入spring坐标 2、dao层的内容与结构 接口 实现类 3、server层的内容与结构 4、创建properties文件 5、配置文件样式 标签头代码:
主要介绍了Spring Boot的properties配置文件读取,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
主要介绍了Spring中属性文件properties的读取与使用详解的相关资料,需要的朋友可以参考下
本篇文章主要介绍了Spring中配置和读取多个Properties文件的方式方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
今天小编就为大家分享一篇关于Spring加载配置和读取多个Properties文件的讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
properties_read_demo.zip
主要介绍了在SpringBoot下读取自定义properties配置文件的方法,文中涉及到了Spring-boot中读取config配置文件的两种方式,需要的朋友可以参考下
主要介绍了详解五种方式让你在java中读取properties文件内容不再是难题 ,非常具有实用价值,需要的朋友可以参考下。
springboot读取配置文件.rar springboot读取配置文件.rar springboot读取配置文件.rar
Spring配置文件中注册三种数据源及从属性文件中读取DB连接四要素
osgi多个bundle之间读取同一配置文件,需要单独添加一个用来读取配置文件的bundle
在本文中我们给大家整理了关于Spring Boot 的配置文件 application.properties的相关知识点内容,需要的朋友们参考学习下。
主要介绍了Spring Boot中配置文件application.properties使用及spring boot读取application.properties文件的方式,需要的朋友参考下吧