关于replacePlaceholders
现在还没有完全验证好,有空看看报错信息
https://www.cnblogs.com/fanguangdexiaoyuer/p/5788432.html
1.目录结构

2.
package cn.caojun.properties; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.util.PropertyPlaceholderHelper;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties; public class CustomPropertyConfigurer extends PropertyPlaceholderConfigurer {
private static Map<String,String> properties = new HashMap<String,String>();
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
// cache the properties
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, false);
for(Map.Entry<Object,Object> entry:props.entrySet()){
String stringKey = String.valueOf(entry.getKey());
String stringValue = String.valueOf(entry.getValue());
//用属性文件键值属性props替换字符串stringValue
stringValue = helper.replacePlaceholders(stringValue, props);
properties.put(stringKey, stringValue);
}
super.processProperties(beanFactoryToProcess, props);
} public static Map<String, String> getProperties() {
return properties;
} public static String getProperty(String key){
return properties.get(key);
}
}
3.property
site=iteye
blog=antlove
url=${site}/${blog}
4.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="SpringDemo" class="cn.caojun.spring.SpringDemo"></bean>
<bean id="propertyConfigurer" class="cn.caojun.properties.CustomPropertyConfigurer">
<property name="locations">
<list>
<value>classpath:cn/caojun/properties/project.properties</value>
</list>
</property>
</bean>
</beans>
5.Main
package cn.caojun.properties; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import java.util.Map; public class Main {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
CustomPropertyConfigurer customPropertyConfigurer=(CustomPropertyConfigurer)applicationContext.getBean("propertyConfigurer");
Map<String,String> properties = customPropertyConfigurer.getProperties();
System.out.println(properties);
}
}
关于replacePlaceholders的更多相关文章
- SPRING多个占位符配置文件解析源码研究--转
原文地址:http://www.cnphp6.com/archives/85639 Spring配置文件: <context:property-placeholder location=&quo ...
- Spring源码学习-PropertyPlaceholderHelper
转载:http://my.oschina.net/ydsakyclguozi/blog/465526 1. CustomPropertyConfigurer.java package property ...
- spring源码解析(一)---占位符解析替换
一.结构类图 ①.PropertyResolver : Environment的顶层接口,主要提供属性检索和解析带占位符的文本.bean.xml配置中的所有占位符例如${}都由它解析 ②.Config ...
- Circular placeholder reference 'server.port' in property definitions
Exception in thread "main" java.lang.IllegalArgumentException: Circular placeholder refere ...
- Circular placeholder reference 'jdbc.driver' in property definitions
Caused by: java.lang.IllegalArgumentException: Circular placeholder reference 'jdbc.driver' in prope ...
- 【ES】ElasticSearch初体验之使用Java进行最基本的增删改查~
好久没写博文了, 最近项目中使用到了ElaticSearch相关的一些内容, 刚好自己也来做个总结. 现在自己也只能算得上入门, 总结下自己在工作中使用Java操作ES的一些小经验吧. 本文总共分为三 ...
- 【Spring源码分析】.properties文件读取及占位符${...}替换源码解析
前言 我们在开发中常遇到一种场景,Bean里面有一些参数是比较固定的,这种时候通常会采用配置的方式,将这些参数配置在.properties文件中,然后在Bean实例化的时候通过Spring将这些.pr ...
- SpringSecurityOauth RCE (CVE-2016-4977) 分析与复现
目录 0x00 前言 0x01 调试分析 0x02 补丁分析 0x03 参考 影响版本: 2.0.0-2.0.9 1.0.0-1.0.5 0x00 前言 这个漏洞与之前那个SpringBoot的SpE ...
- SpringBoot SpEL表达式注入漏洞-分析与复现
目录 0x00前言 0x01触发原因 0x02调试分析 0x03补丁分析 0x04参考文章 影响版本: 1.1.0-1.1.12 1.2.0-1.2.7 1.3.0 修复方案:升至1.3.1或以上版本 ...
随机推荐
- HTTP ERROR 400 Bad Request
一springmvc项目中我新增记录完全ok,编辑就是不行,后台方法进不去.老是报错HTTP ERROR 400 Bad Request. 经过查询,说是400表示请求中的语法错误. 我把新增记录的请 ...
- python爬虫 scrapy2_初窥Scrapy
sklearn实战-乳腺癌细胞数据挖掘 https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campai ...
- bzoj千题计划213:bzoj2660: [Beijing wc2012]最多的方案
http://www.lydsy.com/JudgeOnline/problem.php?id=2660 很容易想到是先把n表示成最大的两个斐波那契数相加,然后再拆分这两个斐波那契数 把数表示成斐波那 ...
- css中实现ul两端的li对齐外面边缘
其实就是设置ul的宽度大一些就好
- 阿里云centos7.3安装lamp环境
参考文档:http://www.jb51.net/article/96649.htm http://m.blog.csdn.net/qq_33813365/article/details/766337 ...
- Apache Oozie Coordinator 作业自定义配置定时任务
一,介绍 Oozie是Hadoop的工作流系统,如果使用Oozie来提交MapReduce作业(Oozie 不仅仅支持MapReduce作业,还支持其他类型的作业),可以借助Oozie Coordin ...
- 怎样提高WebService的性能
服务器端WebService程序: using System.Runtime.Serialization.Formatters.Binary; using System.IO; using Syste ...
- CS229 笔记07
CS229 笔记07 Optimal Margin Classifier 回顾SVM \[ \begin{eqnarray*} h_{w,b}&=&g(w^{\rm T}x+b)\\[ ...
- ARC 之内存转换
CHENYILONG Blog ARC 之内存转换 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilo ...
- python中的__new__、__init__和__del__
__new__.__init__.__del__三个方法用于实例的创建和销毁,在使用python的类中,我们最常用的是__init__方法,通常称为构造方法,__new__方法几乎不会使用,这篇文章是 ...