当前位置: 首页 > 知识库问答 >
问题:

Axon框架:应用事件后聚合标识符必须是非空的

卢志行
2023-03-14

使用axon框架我有一个错误:

应用事件后,聚合标识符必须是非空的。确保在处理创建事件时最迟初始化了聚合标识符。我使用这个StorageEngine:

@Bean
public JdbcEventStorageEngine jdbcEventStorageEngine() throws Exception{
    return new JdbcEventStorageEngine(dataSource::getConnection, NoTransactionManager.INSTANCE);
}
@CommandHandler
public void handle(CreateProductCommand command) throws Exception {
    Aggregate<Product> productAggregate = null;
    try {
      productAggregate = repository.load(command.getId());
    } catch (AggregateNotFoundException exception) {
      logger.info("Aggregate with " + command.getId() + " is not found. Creating new one...");
      productAggregate = repository.newInstance(() -> new Product(command.getId()));
    }
    productAggregate.execute(product -> product.createProduct(command.getId()));
}
@Bean
public EventStorageEngine eventStorageEngine() {
  return new InMemoryEventStorageEngine();
}

共有1个答案

慕容雅珺
2023-03-14

移除spring devtools很好地解决了问题。

 类似资料: