小编Pat*_*Pat的帖子

如何为Joda Period注入配置值

如何使用@Value注释在我的spring bean中配置Joda-Time Period字段?

例如,给定以下组件类:

@Component
public class MyService {

  @Value("${myapp.period:P1D}")
  private Period periodField;
...
}
Run Code Online (Sandbox Code Playgroud)

我想使用标准的ISO8601格式来定义属性文件中的句点.

我收到此错误:

Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.joda.time.Period]: no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:302)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:125)
    at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:61)
    ... 35 more
Run Code Online (Sandbox Code Playgroud)

configuration spring period jodatime

5
推荐指数
2
解决办法
1838
查看次数

标签 统计

configuration ×1

jodatime ×1

period ×1

spring ×1