我今天刚升级到Spring Boot 2.0.2,也是Spring-Data-MongoDB 2.0.7的一部分.
我有以下实体:
@Document
@Data
public class User {
private String username;
private String password;
private List<String> authorities;
public User(String username, String password, List<String> authorities) {
this.username = username;
this.password = password;
this.authorities = authorities;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的测试中,我使用以下内容插入一个新用户:
mongoTemplate.save(new User("testuser", "$2a$04$OuKj.lXzPxlwgr2Jy28E4ehHuxnVZ7BuL46qX9fd6vAijcDN6UeHe", Collections.singletonList("user")));
Run Code Online (Sandbox Code Playgroud)
这在使用Spring Boot 2.0.1(分别是Spring-Data-MongoDB 2.0.6)时非常有效.使用升级的Spring-Data-MongoDB版本,我收到以下错误:
org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.time.ZonedDateTime] for value 'testuser'; nested exception is java.time.format.DateTimeParseException: Text 'testuser' could not be parsed at index 0
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:46)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:191)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) …Run Code Online (Sandbox Code Playgroud)