Axon 框架:聚合标识符在应用事件后必须为非空
Axon framework: Aggregate identifier must be non-null after applying an event
使用轴突框架我遇到错误:
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.
I use this StorageEngine:
@Bean
public JdbcEventStorageEngine jdbcEventStorageEngine() throws Exception{
return new JdbcEventStorageEngine(dataSource::getConnection, NoTransactionManager.INSTANCE);
}
当第二次收到 aggregateId 的消息时代码失败,就像在这个处理程序中一样:
@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();
}
我应该如何为 postgres/mysql 数据库配置 eventStorageEngine?
删除 spring devtools 效果很好。
使用轴突框架我遇到错误:
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. I use this StorageEngine:
@Bean
public JdbcEventStorageEngine jdbcEventStorageEngine() throws Exception{
return new JdbcEventStorageEngine(dataSource::getConnection, NoTransactionManager.INSTANCE);
}
当第二次收到 aggregateId 的消息时代码失败,就像在这个处理程序中一样:
@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();
}
我应该如何为 postgres/mysql 数据库配置 eventStorageEngine?
删除 spring devtools 效果很好。