Spring boot 2 Converting Duration java 8 application.properties

后端 未结 5 1729
抹茶落季
抹茶落季 2021-02-20 08:48

I need to define Duration value (spring.redis.timeout) by application.properties.

I was trying to use one point defined in Spri

5条回答
  •  故里飘歌
    2021-02-20 09:05

    If your Spring-Boot version or its dependencies don't put ApplicationConversionService into context (and Spring-Boot doesn't until 2.1), you can expose it explicitly

    @Bean
    public ConversionService conversionService() {
        return ApplicationConversionService.getSharedInstance();
    }
    

    It invokes Duration.parse, so you may use PT3S, PT1H30M, etc in properties files.

提交回复
热议问题