【发布时间】:2021-01-28 17:51:02
【问题描述】:
如何将我的自定义转换器添加到 mu spring boot 应用程序? 我的实体字段
@CreatedDate
@Column(value = "create_time")
private Instant createTime;
我的转换器是
@Bean
public Converter<Long, Instant> longInstantConverter() {
return new Converter<Long, Instant>() {
@Override
public Instant convert(Long source) {
return Instant.ofEpochMilli(source);
}
};
}
@Bean
public Converter<Instant, Long> instantLongConverter() {
return new Converter<Instant, Long>() {
@Override
public Long convert(@NotNull Instant source) {
return source.toEpochMilli();
}
};
}
我有一个例外
org.springframework.data.mapping.MappingException: Could not read property @org.springframework.data.relational.core.mapping.Column(value=create_time) @org.springframework.data.annotation.CreatedDate()private java.time.Instant com.example.database.model.MyTable.createTime from result set!
.........
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Long] to type [java.time.Instant]
........
我该如何解决,请帮助我!
【问题讨论】:
标签: spring-data-r2dbc r2dbc r2dbc-postgresql