gpt4 book ai didi

spring-boot - org.axonframework.eventsourcing.IncompatibleAggregateException(轴突框架 : Aggregate identifier must be non-null after applying an event)

转载 作者:行者123 更新时间:2023-12-04 02:47:17 24 4
gpt4 key购买 nike

我尝试使用 axon 配置 cqrsevent sourcingSeatReseveCreateCommand 工作正常。但 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 发送请求

这是我的创建请求

enter image description here

这是我的更新请求

enter image description here

更新使这个错误

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com