63 Star 427 Fork 156

huifer/Code-Analysis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
docs
beans
core
AttributeAccessor
Lifecycle
ParameterNameDiscoverer
convert
ConditionalConverter
GenericConverter
TypeConverter
images
Readme.md
Spring-ConditionalConverter.md
Spring-ConfigurableConversionService.md
Spring-ConversionService.md
Spring-Converter.md
Spring-ConverterRegistry.md
Spring-DefaultConversionService.md
Spring-DefaultFormattingConversionService.md
Spring-FormatterRegistry.md
Spring-FormattingConversionService.md
Spring-GenericConversionService.md
Spring-GenericConverter.md
Spring-TypeConverter.md
Spring-TypeDescriptor.md
io
registry
env
other
utils
release
.gitattributes
.gitignore
CHANGELOG.MD
LICENSE
Notice
README.md
_coverpage.md
index.html
summary.md
todo.md
克隆/下载
Spring-DefaultConversionService.md 1.93 KB
一键复制 编辑 原始数据 按行查看 历史

Spring DefaultConversionService

  • 类全路径: org.springframework.core.convert.support.DefaultConversionService
  • 类图

DefaultConversionService.png

  • 构造方法分析
    • org.springframework.core.convert.support.DefaultConversionService#DefaultConversionService
public DefaultConversionService() {
   addDefaultConverters(this);
}

	public static void addDefaultConverters(ConverterRegistry converterRegistry) {
		addScalarConverters(converterRegistry);
		addCollectionConverters(converterRegistry);

		converterRegistry.addConverter(new ByteBufferConverter((ConversionService) converterRegistry));
		converterRegistry.addConverter(new StringToTimeZoneConverter());
		converterRegistry.addConverter(new ZoneIdToTimeZoneConverter());
		converterRegistry.addConverter(new ZonedDateTimeToCalendarConverter());

		converterRegistry.addConverter(new ObjectToObjectConverter());
		converterRegistry.addConverter(new IdToEntityConverter((ConversionService) converterRegistry));
		converterRegistry.addConverter(new FallbackObjectToStringConverter());
		converterRegistry.addConverter(new ObjectToOptionalConverter((ConversionService) converterRegistry));
	}
  • 从类图上我们可以知道 DefaultConversionService 实现了ConverterRegistry , 这这里构建阶段的时候会放入spring中编写好的convert实现类. 方便后续使用

  • 该类还有一个对外方法 getSharedInstance

public static ConversionService getSharedInstance() {
   DefaultConversionService cs = sharedInstance;
   if (cs == null) {
      synchronized (DefaultConversionService.class) {
         cs = sharedInstance;
         if (cs == null) {
            cs = new DefaultConversionService();
            sharedInstance = cs;
         }
      }
   }
   return cs;
}
  • 从代码上也不难看出也是创建 DefaultConversionService 将spring中编写好的convert放入容器等待后续使用.
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/pychfarm_admin/code-analysis.git
git@gitee.com:pychfarm_admin/code-analysis.git
pychfarm_admin
code-analysis
Code-Analysis
v0.0.15

搜索帮助