java - Javers - java.lang.ClassCastException: org.javers.core.diff.changetype.ValueChange 不能转换为 org.javers.core.diff.changetype.map.MapChange
问题描述
我在使用 Spring Boot Javers 示例时遇到错误。
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:816) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:797) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at com.example.SpringbootJaVersApplication.main(SpringbootJaVersApplication.java:37) [classes/:na]
Caused by: java.lang.ClassCastException: org.javers.core.diff.changetype.ValueChange cannot be cast to org.javers.core.diff.changetype.map.MapChange
at com.example.SpringbootJaVersApplication.withJavers(SpringbootJaVersApplication.java:118) [classes/:na]
at com.example.SpringbootJaVersApplication.run(SpringbootJaVersApplication.java:49) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:813) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
... 5 common frames omitted
代码:
List<Change> snapshots = javers.findChanges(QueryBuilder.byInstanceId(c.getId(), Car.class).build());
for (Change ch : snapshots) {
if(ch instanceof ValueChange) {
System.out.println("Change is an instance of value change...");
ValueChange vc = (ValueChange) ch;
System.out.println(vc.getPropertyName());
System.out.println(vc.getAffectedGlobalId());
System.out.println(vc.getLeft()+" "+vc.getRight());
}
if(ch instanceof PropertyChange) {
PropertyChange pc = (PropertyChange)ch;
System.out.println(pc.getPropertyName());
System.out.println(pc.getAffectedGlobalId());
MapChange mc = (MapChange)pc;
System.out.println(mc.getPropertyName());
}
}
解决方案
推荐阅读
- c# - 使用 unmamagedexports 从 Access VBA 调用 C# DLL 时出现 VBA 错误 49 和错误 424
- laravel - 如何在有作业运行时将 laravel 部署到 docker 容器中
- java - 使用数据库实现 Rest 测试
- performance - Kotlin 中的 get 和 [] 有什么区别?
- django - Django:每小时重置模型的特定字段
- java - 拒绝访问从 firebase 检索数据
- vuejs2 - Vue.js 3.2.1 下 Gauge.js 组件未创建
- sql-server - 用于转置的重复案例函数
- typescript - 如何键入检查内存中的 TypeScript 代码片段?
- python - 如何使用 UDP 和 Asyncio 进行从服务器到客户端的多个文件传输 - python