spring-boot - spring boot 版本升级后如何使用 Converter 修复异常
问题描述
我最近从 Spring Boot 版本 1.5.7 升级到了 2.1.4。升级后,我遇到了转换器异常,其中@Query 注释与弹簧数据一起使用。下面的异常堆栈跟踪。
您能否建议是否应更改任何依赖版本以解决此问题?还是需要编写客户转换器?
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.HashMap<?, ?>] to type [@org.springframework.data.jpa.repository.Query com.example.Stage.XXXX]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194)
at org.springframework.core.convert.support.CollectionToCollectionConverter.convert(CollectionToCollectionConverter.java:89)
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
... 150 more
贴出的代码:
@RepositoryRestResource
public interface FileStagedEventRepository extends JpaRepository<FileStagedEvent, Long> {
@Query(value = "select new map(id as id, fileName as fileName, recType as recType) FROM FileStagedEvent where id = :id", nativeQuery = true)
public Map<String, String> findById(@Param("id") Long id);
}
该select new map
部分似乎是问题所在。我不确定这个地图功能是如何工作的。
解决方案
推荐阅读
- cordova - 我可以从另一个应用程序打开我的 ionic 应用程序吗?
- javascript - 生成随机颜色时如何修复颜色闪烁
- r - 文件中的错误:使用 read.xlsx() 时的“描述”参数无效
- sql - 根据公共列值将定义的行数转换为列
- android - 使用 ML-Kit 从收据中获取总和
- python - 当我构建用于自动生成源代码注释的深度学习模型时。我得到以下错误
- javascript - 在 Liquid 中悬停时循环遍历图像
- ssis - SSIS ForEach 循环容器 - 如何在运行时动态更改 OLEDB 目标连接
- java - java - 如何在使用java的rest调用中始终调用相同的套接字?
- python - python pandas根据行值解析字符串