作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 axon 配置 cqrs 和 event sourcing。SeatReseveCreateCommand 工作正常。但 SeatReserveUpadateCommand 无法正常工作。
这是我的 SeatReserve aggregate
@Aggregate
public class SeatReserve {
@AggregateIdentifier
private String id;
private String seatid;
private Date date;
@SuppressWarnings("unused")
private SeatReserve() {
}
@CommandHandler
public SeatReserve(SeatReseveCreateCommand seatReseveCreateCommand) {
apply(new SeatReseveCreateEvent(seatReseveCreateCommand.getMyid(), seatReseveCreateCommand.getSeatId(),
seatReseveCreateCommand.getDate()));
}
@CommandHandler
public SeatReserve(SeatReserveUpadateCommand upadateCommand) {
apply(new SeatReserveUpadateEvent(id, upadateCommand.getSeatId()));
}
@EventSourcingHandler
public void on(SeatReseveCreateEvent seatReseveCreateEvent) {
this.id = seatReseveCreateEvent.getId();
this.seatid = seatReseveCreateEvent.getSeatId();
this.date = seatReseveCreateEvent.getDate();
}
@EventSourcingHandler
public void on(SeatReserveChangeEvent upadateEvent) {
seatid = upadateEvent.getSeatId();
}
}
这是我的 Controller
@RestController
public class TestController {
private final CommandGateway commandGateway;
public TestController(CommandGateway commandGateway) {
this.commandGateway=commandGateway;
}
@PostMapping
public String fileComplaint(@RequestBody Map<String, String> request) {
String id = UUID.randomUUID().toString();
SeatReseveCreateCommand command=new SeatReseveCreateCommand(id,request.get("seatid"),new Date(request.get("date")));
commandGateway.send(command);
return id;
}
@PatchMapping
public String fileComplaintUpdate(@RequestBody Map<String, String> request) {
SeatReserveUpadateCommand command= new SeatReserveUpadateCommand(request.get("id"),request.get("seatid"));
commandGateway.send(command);
return request.get("id");
}
}
我尝试使用 postman 发送请求
这是我的创建请求
这是我的更新请求
更新使这个错误
2018-01-03 10:44:53.608 WARN 11138 --- [nio-8085-exec-1] o.a.c.gateway.DefaultCommandGateway : Command 'com.thamira.research.api.bankaccount.SeatReserveUpadateCommand' resulted in org.axonframework.eventsourcing.IncompatibleAggregateException(Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event.)
我该如何解决这个问题。
最佳答案
问题是您的更新命令被定义为构造函数。该命令应该转到已经存在的聚合实例。
将命令处理程序更改为:
@CommandHandler
public void handle(SeatReserveUpadateCommand upadateCommand) {...}
应该可以解决问题。
关于spring-boot - org.axonframework.eventsourcing.IncompatibleAggregateException(轴突框架 : Aggregate identifier must be non-null after applying an event),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48071720/
我尝试使用 axon 配置 cqrs 和 event sourcing。SeatReseveCreateCommand 工作正常。但 SeatReserveUpadateCommand 无法正常工作。
我是一名优秀的程序员,十分优秀!