Spring的PropertyPlaceholderConfigurer
来源:互联网 发布:淘宝申诉怎么写 编辑:程序博客网 时间:2024/05/05 01:02
使用PropertyPlaceholderConfigurer将系统相关变量分离懂到一个properties文件中,便于系统移植、切换。
<beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /><property name="ignoreResourceNotFound" value="true" /><property name="locations"><list><!-- 标准配置 --><value>classpath*:/application.properties</value></list></property></bean>
官方注释:
A property resource configurer that resolves placeholders in bean property values of context definitions. It pulls values from a properties file into bean definitions.
The default placeholder syntax follows the Ant / Log4J / JSP EL style:
${...}Example XML context definition:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"><value>${driver}</value></property> <property name="url"><value>jdbc:${dbname}</value></property> </bean>Example properties file:
driver=com.mysql.jdbc.Driver dbname=mysql:mydbPropertyPlaceholderConfigurer checks simple property values, lists, maps, props, and bean names in bean references. Furthermore, placeholder values can also cross-reference other placeholders, like:
rootPath=myrootdir subPath=${rootPath}/subdirIn contrast to PropertyOverrideConfigurer, this configurer allows to fill in explicit placeholders in context definitions. Therefore, the original definition cannot specify any default values for such bean properties, and the placeholder properties file is supposed to contain an entry for each defined placeholder.
If a configurer cannot resolve a placeholder, a BeanDefinitionStoreException will be thrown. If you want to check against multiple properties files, specify multiple resources via the "locations" setting. You can also define multiple PropertyPlaceholderConfigurers, each with its own placeholder syntax.
Default property values can be defined via "properties", to make overriding definitions in properties files optional. A configurer will also check against system properties (e.g. "user.dir") if it cannot resolve a placeholder with any of the specified properties. This can be customized via "systemPropertiesMode".
Note that the context definition is aware of being incomplete; this is immediately obvious to users when looking at the XML definition file. Hence, placeholders have to be resolved; any desired defaults have to be defined as placeholder values as well (for example in a default properties file).
Property values can be converted after reading them in, through overriding the PropertyResourceConfigurer.convertPropertyValue(java.lang.String)
method. For example, encrypted values can be detected and decrypted accordingly before processing them.
参考:
http://thomaslee007.iteye.com/blog/167762
- spring的好处--PropertyPlaceholderConfigurer
- spring的好处--PropertyPlaceholderConfigurer
- spring的 PropertyPlaceholderConfigurer配置
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer
- Spring PropertyPlaceholderConfigurer的使用
- Spring PropertyPlaceholderConfigurer的使用
- spring propertyplaceholderconfigurer的使用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer使用
- Spring:PropertyPlaceholderConfigurer的使用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Spring的PropertyPlaceholderConfigurer应用
- Log4j使用笔记
- msclass实例 jquery 通用滚动特效,文字单行,多行停留滚动,图文上下左右滚动
- java 静态块与非静态块的执行顺序
- Lucence使用笔记
- GOF23种设计模式趣谈(转载)
- Spring的PropertyPlaceholderConfigurer
- web.xml 中的listener、 filter、servlet 加载顺序及其详解(转载)
- USB协通讯议--深入理解
- 使用plsql执行计划进行sql调优(转载)
- iframe使用笔记
- SQL优化笔记
- oracle中使用序列和触发器实现单个字段值自增长
- BOM对象
- freemarker中三木表达式的用法