You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AggregateTestFixture.registerIgnoredField忽略抽象父类字段失效问题问询

Axon Framework测试Fixture忽略父类字段问题:Bug还是预期特性?

问题场景

抽象类AbstractUitworpAggregateEvent中的字段uitworpAggregateId无法被Fixture的registerIgnoredField()方法识别,但子类UitworpAggregateAanmakenEvent自身的字段gebeurtenisId可正常识别。

使用版本:

  • Spring Boot 3.4.1
  • Axon Framework 4.10.4
  • Java 21

测试代码

FixtureConfiguration<MyAggregate> fixture = new AggregateTestFixture(MyAggregate.class);

@Test
void myTest(){
  fixture.registerIgnoredField(UitworpAggregateAanmakenEvent.class, "uitworpAggregateId");
}

事件类定义

@EqualsAndHashCode
@Getter
@SuperBuilder(toBuilder = true)
@ToString
public abstract class AbstractUitworpAggregateEvent {
    public UUID uitworpAggregateId;
    public UUID myAggregateId;
}

@EqualsAndHashCode(callSuper = true)
@Getter
@Jacksonized
@SuperBuilder(toBuilder = true)
@ToString(callSuper = true)
public class UitworpAggregateAanmakenEvent extends AbstractUitworpAggregateEvent {
    private final UUID gebeurtenisId;
}

问题根源

查看Axon Framework源码发现,org.axonframework.test.matchers.IgnoreField类的构造方法仅在传入的类本身查找字段,未遍历父类层级:

public IgnoreField(Class<?> clazz, String fieldName) {
    try {
        ignoredField = clazz.getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
        throw new FixtureExecutionException("The given field does not exist", e);
    }
}

疑问与临时方案

将上述代码中的ignoredField = clazz.getDeclaredField(fieldName);修改为ignoredField = clazz.getSuperclass().getDeclaredField(fieldName);后,当前问题可解决,但存在以下疑问:

  1. 该问题属于Axon Framework的Bug还是预期特性?
  2. 上述修改方案是否正确,是否会引发其他潜在问题?

内容的提问来源于stack exchange,提问作者Jan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 19:32:10