在项目搭建过程中,发现Spring加载配置文件总提示配置项不存在,而现实情况是配置项是存在的。网上搜索了一下,最后通过增加如下配置解决。
<property name="ignoreUnresolvablePlaceholders" value="true" />
于是,网上找到如下这遍文章,转载记录一下。
PropertyPlaceholderConfigurer类是用来解析Java Properties属性文件值,并提供在spring配置期间替换使用属性值。以下是它的三种常见使用方法。
一.基本的使用方法
spring-config.xml
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>classpath:/spring/include/dbQuery.properties</value> </property> </bean>
其中classpath是引用src目录下的文件写法。
二.当存在多个Properties文件时,配置就需使用locations了
spring-config.xml
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:/spring/include/jdbc-parms.properties</value> <value>classpath:/spring/include/base-config.properties</value> </list> </property> </bean>
三.接下来我们要使用多个PropertyPlaceholderConfigurer来分散配置,达到整合多工程下的多个分散的Properties文件,其配置如下
<bean id="propertyConfigurerForProject1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="order" value="1" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="location"> <value>classpath:/spring/include/dbQuery.properties</value> </property> </bean>
<bean id="propertyConfigurerForProject2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="order" value="2" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="locations"> <list> <value>classpath:/spring/include/jdbc-parms.properties</value> <value>classpath:/spring/include/base-config.properties</value> </list> </property> </bean>
其中order属性代表其加载顺序,而ignoreUnresolvablePlaceholders为是否忽略不可解析的Placeholder,如配置了多个PropertyPlaceholderConfigurer,则需设置为true。
相关推荐
Spring中PropertyPlaceholderConfigurer的使用
Spring属性占位符PropertyPlaceholderConfigurer的使用,自己写的一个demo
主要介绍了Spring如何使用PropertyPlaceholderConfigurer读取文件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
NULL 博文链接:https://wokeke.iteye.com/blog/2214113
4.9.1.PropertyPlaceholderConfigurer类 4.9.1.1.使用环境变量进行替换 4.9.2.PropertyOverrideConfigurer类 4.10.使用alias节点为对象添加别名 4.11.IApplicationContext简介 4.12.配置应用程序上下文 4.12.1.注册...
6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 6.8.1.1. @Configurable object的单元测试 6.8.1.2. 多application context情况下的处理 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来...
不使用XML定义档进行 Bean设置 Aware 相关介面 BeanPostProcessor BeanFactoryPostProcessor PropertyPlaceholderConfigurer PropertyOverrideConfigurer CustomEditorConfigurer ...
6 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 7 8 9 <value>/WEB-INF/jdbc.properties 10 11 12 13 14 它配置了以下功能: 读取...
NULL 博文链接:https://chyy001.iteye.com/blog/1338488
4.8.2.1 示例:PropertyPlaceholderConfigurer. 82 4.8.2.2 示例:PropertyOverrideConfigurer 83 4.8.3 使用FactoryBean 来自定义实例化逻辑. 84 4.9 基于注解的容器配置. 85 4.9.1 @Required....
#Spring 属性注释扩展的 PropertyPlaceHolderConfigurer 使用注解将配置属性注入到 Spring 组件中。 注意:Spring 3 现在支持使用 @Value 注释的容器的。 该项目仅用于 Spring 2.5.x 支持。 ##入门Spring房产注解...
JDBCTemp+MySQL示例。Spring,PropertyPlaceholderConfigurer,BeanPropertyRowMapper
在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面...<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>classpath:proxool.properties ...
spring3.1中文参考文档,南磊翻译,现在有4章,目录如下: 第一部分 Spring framework概述.......................................................................................................................
PropertyPlaceholderConfigurer PropertyResourceConfigurer PropertyValue PropertyValues PropertyValuesEditor PrototypeAspectInstanceFactory PrototypeTargetSource ProxyConfig ProxyFactory ...
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>WEB-INF/jdbc.properties class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-...
// 所有符合pointcut条件的类或方法,都执行myAdvice建议,advice里定义了,所有的save方法,find方法都要执行transactionManager这个切面。 // 并且save方法的事物是必须的,find方法是只读的。 --> ---------...
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
什么 与通过从属性文件读取其配置来进行自我配置相比,对于应用程序而言,有什么可能更简单? 好吧,对于业务应用程序而言... 首先,我们将使用PropertyPlaceholderConfigurer通过读取存储在.properties文件中的属性来