关于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或以上版本 ...
随机推荐
- 关于Thinkphp5类命名导致的“模块不存在”问题
不得不说,thinkphp5就是个十足的坑货, 在thinkphp3.2.3的基础上,函数.用法变了也就忍了, 在mac下写的一个类文件 GetRedisData.php,在mac+mamp环境下是正 ...
- python---django使用cookie和session
在views中的调用: def login(req): message='' if req.method == "POST": user = req.POST.get(" ...
- bzoj千题计划241:bzoj3864: Hero meet devil
http://www.lydsy.com/JudgeOnline/problem.php?id=3864 题意: 给你一个DNA序列,求有多少个长度为m的DNA序列和给定序列的LCS为0,1,2... ...
- 用Canvas做动画
之前看过不少HTML5动画的书,讲解的是如何去做,对于其中的数学原理讲解的不详细,常有困惑.最近看的<HTML5+JavaScript 动画基础>这个是译本,Keith Peters曾写过 ...
- Asp.Net中索引器的用法
索引器定义类似于属性,但其功能与属性并不相同.索引器提供一种特殊的方法编写get和set访问器.属性可以像访问字段一样访问对象的数据,索引器可以使用户像访问数组一样访问类成员. 一.索引器特性 1.g ...
- 用Emacs将文件加密保存
为Emacs安装ps-ccrypt插件. 如果你在使用elpa(Emacs的一个插件管理器), 可以M-x list-packages, 从插件列表中找到 ps-ccrypt, 在该项上按i将其标记为 ...
- spring如何管理mybatis(二) ----- SqlSession的线程安全性
在之前的文章中我们了解到最终的数据库最终操作是走的代理类的方法: @Override public Object invoke(Object proxy, Method method, Object[ ...
- VS 多工程代码编写
VS工作目录,输出目录 C++项目,解决方案总文件夹下就只包含解决方案配置文件sln和一个项目总文件夹和一个Debug文件夹以及一个Release文件夹(共四个东东,其中Debug和Release文件 ...
- [Alg::DP] 袋鼠过河
一道简单的动态规划问题. 题目来源:牛客网 链接:https://www.nowcoder.com/questionTerminal/74acf832651e45bd9e059c59bc6e1cbf ...
- 修改history记录数门限
你的 Bash 命令历史保存的历史命令的数量可以在 ~/.bashrc 文件里设置.在这个文件里,你可以找到下面两行: HISTSIZE=1000 HISTFILESIZE=2000 HISTSIZE ...