小编Mic*_*ger的帖子

Spring-Data-MongoDB:无法使用自定义转换器将升级后的类型转换为2.0.7

我今天刚升级到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)

java spring spring-data-mongodb spring-boot

6
推荐指数
1
解决办法
1659
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1

spring-data-mongodb ×1