这个配置可以使得springboot支持从yml文件读取string自定转换为ZonedDateTime
@Bean
public ConversionService conversionService() {
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
factory.setFormatterRegistrars(Collections.singleton(registrar));
factory.afterPropertiesSet();
return factory.getObject();
}
网友评论