美文网首页
2021-11-01 springboot Configurat

2021-11-01 springboot Configurat

作者: scoot929 | 来源:发表于2021-11-04 15:20 被阅读0次

这个配置可以使得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();
  }

相关文章

网友评论

      本文标题:2021-11-01 springboot Configurat

      本文链接:https://www.haomeiwen.com/subject/xcrkzltx.html