为什么80%的码农都做不了架构师?>>>   

基于spring 4.0.9

你的spring配置文件

http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd

spring-beans.jar - /META-INF/spring.schemas

找到语法校验文件

http\://www.springframework.org/schema/util/spring-util-4.0.xsd=org/springframework/beans/factory/xml/spring-util-4.0.xsd
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-4.0.xsd

spring-beans.jar - /META-INF/spring.handlers

找到命名空间对应的实现类

http\://www.springframework.org/schema/util=org.springframework.beans.factory.xml.UtilNamespaceHandler

org.springframework.beans.factory.xml.UtilNamespaceHandler

@Override
public void init() {registerBeanDefinitionParser("constant", new ConstantBeanDefinitionParser());registerBeanDefinitionParser("property-path", new PropertyPathBeanDefinitionParser());registerBeanDefinitionParser("list", new ListBeanDefinitionParser());registerBeanDefinitionParser("set", new SetBeanDefinitionParser());registerBeanDefinitionParser("map", new MapBeanDefinitionParser());registerBeanDefinitionParser("properties", new PropertiesBeanDefinitionParser()); // 重点
}

org.springframework.beans.factory.xml.UtilNamespaceHandler.PropertiesBeanDefinitionParser

private static class PropertiesBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {@Overrideprotected Class<?> getBeanClass(Element element) {return PropertiesFactoryBean.class; // 重点}
}

org.springframework.beans.factory.config.PropertiesFactoryBean

注意它实现了FactoryBean<Properties>InitializingBean两个接口,就要实现这两个方法

@Override
public final void afterPropertiesSet() throws IOException {if (this.singleton) {this.singletonInstance = createProperties(); // 重点}
}@Override
public final Properties getObject() throws IOException {if (this.singleton) {return this.singletonInstance;} else {return createProperties(); // 重点}
}

Properties org.springframework.beans.factory.config.PropertiesFactoryBean.createProperties()

protected Properties createProperties() throws IOException {return mergeProperties(); // 直接调用父类的方法
}

Properties org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties() 中

protected Properties mergeProperties() throws IOException {Properties result = new Properties();if (this.localOverride) {// Load properties from file upfront, to let local properties override.loadProperties(result); // 重点}if (this.localProperties != null) {for (Properties localProp : this.localProperties) {CollectionUtils.mergePropertiesIntoMap(localProp, result);}}if (!this.localOverride) {// Load properties from file afterwards, to let those properties override.loadProperties(result); // 重点}return result;
}

Properties org.springframework.core.io.support.PropertiesLoaderSupport(Properties props) 中

protected void loadProperties(Properties props) throws IOException {if (this.locations != null) {for (Resource location : this.locations) {if (logger.isInfoEnabled()) {logger.info("Loading properties file from " + location);}try {PropertiesLoaderUtils.fillProperties(props, new EncodedResource(location, this.fileEncoding), this.propertiesPersister); // 重点}catch (IOException ex) {if (this.ignoreResourceNotFound) {if (logger.isWarnEnabled()) {logger.warn("Could not load properties from " + location + ": " + ex.getMessage());}}else {throw ex;}}}}
}

发现了fileEncoding,那么就可以根据具体情况设置了。

转载于:https://my.oschina.net/ojeta/blog/800285

util:properties/加载的配置文件中有中文导致乱码,如何通过分析源码解决问题?...相关推荐

  1. 【Android 安全】DEX 加密 ( 多 DEX 加载 | 65535 方法数限制和 MultiDex 配置 | PathClassLoader 类加载源码分析 | DexPathList )

    文章目录 一.65535 方法数限制和 MultiDex 配置 二.多 DEX 加载引入 三.PathClassLoader 类加载源码分析 四.BaseDexClassLoader 类加载源码分析 ...

  2. 框架源码专题:springIOC的加载过程,bean的生命周期,结合spring源码分析

    文章目录 1.BeanFactory和ApplicationContext的区别? 2. IOC与 Bean的加载过程 ①:初始化容器DefaultListableBeanFactory ②:创建读取 ...

  3. Android图片加载框架最全解析(二),从源码的角度理解Glide的执行流程

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/53939176 本文同步发表于我的微信公众号,扫一扫文章底部的二维码或在微信搜索 郭 ...

  4. android 新闻应用、Xposed模块、酷炫的加载动画、下载模块、九宫格控件等源码...

    Android精选源码 灵活的ShadowView,可替代CardView使用 基于Tesseract-OCR实现自动扫描识别手机号 Android播放界面仿QQ音乐开源音乐播放器 新闻应用项目采用了 ...

  5. android 新闻应用、Xposed模块、酷炫的加载动画、下载模块、九宫格控件等源码

    Android精选源码 灵活的ShadowView,可替代CardView使用 基于Tesseract-OCR实现自动扫描识别手机号 Android播放界面仿QQ音乐开源音乐播放器 新闻应用项目采用了 ...

  6. android 新闻应用、Xposed模块、酷炫的加载动画、下载模块、九宫格控件等源码... 1

    Android精选源码 灵活的ShadowView,可替代CardView使用 基于Tesseract-OCR实现自动扫描识别手机号 Android播放界面仿QQ音乐开源音乐播放器 新闻应用项目采用了 ...

  7. Spring Boot @PropertySource注解加载指定配置文件(五)

    我们可以通过@ConfigurationProperties和@Value两个注解获取主配置文件application.properties 或 apllication.yml中的配置信息,但是如果我 ...

  8. @value 静态变量_Spring注解驱动开发之八——@Value属性赋值、@PropertySource 加载外部配置文件...

    本文包含以下内容: 建立新的配置类 建立新的测试方法 通过@Value 进行赋值 通过@PropertySource  加载配置文件,并进行注入 拓展@Value  .@PropertySource ...

  9. mybatis加载xml配置文件

    <build><finalName>bizcloud-tcb2b</finalName><!-- mybatis加载xml配置文件的配置 -->< ...

最新文章

  1. Docker安装Apache与运行简单的web服务——httpd helloworld
  2. Spring Boot第二篇:Spring Boot配置文件详解
  3. C++阶段01笔记01【C++初识(第一个C++程序、注释、变量、常量、关键字、标识符命名规则)】
  4. tf.Variable 和 tf.get_variable的区别(2)
  5. 参数调优为什么要采样_3年Java外包,内推阿里过关斩将,最后却倒在调优经验上! - Java架构师追风...
  6. 老板要做数字化转型,干了3个月的脏活累活,我被开除了
  7. uploadify 3.2 后台动态传参数
  8. python urllib下载文件怎么停止_python下载文件的三种方法
  9. SpringMVC文件上传(一)
  10. 物联网操作系统进入收敛期
  11. Scrapy框架的使用之Spider Middleware的用法
  12. C语言实现移位密码算法,仿射密码算法
  13. c语言程序电子词典,C语言及程序设计进阶例程-14 开发一个电子词典
  14. 怎么添加桌面计算机快捷键,怎么添加桌面快捷方式图标,教你怎么添加桌面快捷方式图标...
  15. 内核编译出现Memory exhausted解决方案
  16. Release That Record Lock!
  17. fastq文件转化成bam文件
  18. 合肥工业大学计算机保研,合肥工大(合肥工业大学保研去向)
  19. 教资初级中学计算机真题,初中信息技术教资面试真题:VB程序设计语言的操作环境...
  20. Altium Designer生产文件输出与文件归档

热门文章

  1. git fatal: index file smaller than expected
  2. SQL Server2005 日期字段与字符串比较的怪异问题
  3. 微软6月补丁日修复7个0day:6个已遭利用且其中1个是为 APT 服务的商用exploit
  4. 近300个 Windows 10 可执行文件易受 DLL 劫持攻击
  5. 使用audit工具常规命令监控系统访问文件
  6. 图解 hexo + github 从零快速 搭建个人博客 windowss
  7. XWiki 6.3 M1 发布,Java 的 Wiki 系统
  8. CentOS设置静态IP
  9. 23种设计模式类图总结
  10. 老李分享:HTTP session原理及应用 1