我试图将我的项目提升到最新的Spring Boot 2.0.0里程碑(编写本文时的M4)并且我一直在为一个丢失的转换器(ZonedDateTime到java.util.Date)获得一个例外,尽管它已经明确配置了 - 至少对我来说.这是代码和堆栈跟踪:
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import java.time.ZonedDateTime;
import java.util.Date;
@Component
public class ZonedDateTimePersistenceConverter implements Converter<ZonedDateTime, Date> {
@Nullable
@Override
public Date convert(ZonedDateTime source) {
return Date.from(java.time.ZonedDateTime.now().toInstant());
}
}
Run Code Online (Sandbox Code Playgroud)
在调用相应的Spring Data REST端点时,我得到:
2017-09-17 21:07:53.634 ERROR 1894 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.time.ZonedDateTime] to type [java.util.Date]] with root cause
org.springframework.core.convert.ConverterNotFoundException: No …Run Code Online (Sandbox Code Playgroud)