Axon框架:应用事件后,聚合标识符必须为非null

时间:2017-02-23 17:15:06

标签: java axon

使用axon框架我有错误:

  

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

julia> function f(x::Float64)
         const x_const::Float64 = x;
         x_const = "helle"; # this will break, as expected
       end

第二次收到aggregateId的消息时代码失败,就像在此处理程序中一样:

@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()));
}

我应该如何为postgres / mysql数据库配置eventStorageEngine?

1 个答案:

答案 0 :(得分:1)

删除弹簧开发工具效果很好。