AggregateMember 继承:没有处理程序订阅命令
AggregateMember inheritance: No handler was subscribed to command
我有以下聚合,其中包含一个聚合成员。
@Aggregate
public class CpaAggregate {
@AggregateIdentifier
private String externalId;
@AggregateMember
private Entity entity;
public CpaAggregate() {
}
@CommandHandler
public CpaAggregate(CreateCpaCommand cmd) {
AggregateLifecycle.apply(new CpaCreatedEvent(...));
}
@EventSourcingHandler
protected void on(CpaCreatedEvent evt) {
....
}
}
public class Entity {
@EntityId
private String entityId;
private Set<Identifier> identifiers = new HashSet<>();
public Entity() {
}
@EventSourcingHandler
public void on(IdentifiantUpdatedEvent evt) {
...
}
}
public class Laboratory extends Entity {
private OperatingSystem operatingSystem;
public Laboratory() {
}
@CommandHandler
public void handle(UpdateIdentifierLABCommand cmd) {
AggregateLifecycle.apply(new IdentifiantUpdatedEvent(....));
}
}
.
commandGateway.sendAndWait(new UpdateIdentifierLABCommand(...));
当我发送更新实验室类型实体标识符的命令时,出现此错误
org.axonframework.commandhandling.NoHandlerForCommandException: No
handler was subscribed to command [UpdateIdentifierLABCommand]
Aymen,我会为您的 CpaAggregate
建模略有不同。
我不会使用通用的 Entity
聚合成员,而是使用更具体的实体,例如 Laboratory
实例。
一方面,随着模型结构变得更加清晰,这一点变得更加清晰 modeling-wise。其次,Axon Framework 将向上移动到父 class 以了解具体情况。因此,您仍然可以在 Entity
class 中拥有公共信息,例如实体标识符、命令处理程序和事件源处理程序。
因此我会这样调整它:
@Aggregate
public class CpaAggregate {
@AggregateIdentifier
private String externalId;
@AggregateMember
private Laboratory laboratory;
public CpaAggregate() {
}
@CommandHandler
public CpaAggregate(CreateCpaCommand cmd) {
AggregateLifecycle.apply(new CpaCreatedEvent(...));
}
@EventSourcingHandler
protected void on(CpaCreatedEvent evt) {
....
}
}
顺便说一句,这应该确保 Axon Framework 也能在聚合成员中发现命令处理程序。
我有以下聚合,其中包含一个聚合成员。
@Aggregate
public class CpaAggregate {
@AggregateIdentifier
private String externalId;
@AggregateMember
private Entity entity;
public CpaAggregate() {
}
@CommandHandler
public CpaAggregate(CreateCpaCommand cmd) {
AggregateLifecycle.apply(new CpaCreatedEvent(...));
}
@EventSourcingHandler
protected void on(CpaCreatedEvent evt) {
....
}
}
public class Entity {
@EntityId
private String entityId;
private Set<Identifier> identifiers = new HashSet<>();
public Entity() {
}
@EventSourcingHandler
public void on(IdentifiantUpdatedEvent evt) {
...
}
}
public class Laboratory extends Entity {
private OperatingSystem operatingSystem;
public Laboratory() {
}
@CommandHandler
public void handle(UpdateIdentifierLABCommand cmd) {
AggregateLifecycle.apply(new IdentifiantUpdatedEvent(....));
}
}
.
commandGateway.sendAndWait(new UpdateIdentifierLABCommand(...));
当我发送更新实验室类型实体标识符的命令时,出现此错误
org.axonframework.commandhandling.NoHandlerForCommandException: No handler was subscribed to command [UpdateIdentifierLABCommand]
Aymen,我会为您的 CpaAggregate
建模略有不同。
我不会使用通用的 Entity
聚合成员,而是使用更具体的实体,例如 Laboratory
实例。
一方面,随着模型结构变得更加清晰,这一点变得更加清晰 modeling-wise。其次,Axon Framework 将向上移动到父 class 以了解具体情况。因此,您仍然可以在 Entity
class 中拥有公共信息,例如实体标识符、命令处理程序和事件源处理程序。
因此我会这样调整它:
@Aggregate
public class CpaAggregate {
@AggregateIdentifier
private String externalId;
@AggregateMember
private Laboratory laboratory;
public CpaAggregate() {
}
@CommandHandler
public CpaAggregate(CreateCpaCommand cmd) {
AggregateLifecycle.apply(new CpaCreatedEvent(...));
}
@EventSourcingHandler
protected void on(CpaCreatedEvent evt) {
....
}
}
顺便说一句,这应该确保 Axon Framework 也能在聚合成员中发现命令处理程序。