外部java文件中的eventandler未被触发



我有一个Aggregate类,它有

  1. CommandHandler接收到CreateAccountCommand

  2. 1EventSourceHandling接收AccountCreatedEvent

相应地,在其他包中,我用@EventHandler代替AccountCreatedEvent。但是,它没有被调用。

@Component
class EventHandlingComponent {
@Autowired AccountRepository repo; 
@EventHandler
public void on(AccountCreatedEvent event ) 
{
// save to repository ; 
}
}

我正在使用spring boot应用程序,并将此添加为依赖项

<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-spring-boot-starter</artifactId>
<version>4.5.3</version>
<exclusions>
<exclusion>
<groupId>org.axonframework</groupId>
<artifactId>axon-server-connector</artifactId>
</exclusion>
</exclusions>
</dependency>

如果有人能指出我所犯的错误,我会非常感激。

事件处理程序类是否在一个包中,该包是主类包的子包?否则,默认情况下,扫描器将找不到该类。在这种情况下,你必须配置Spring启动应该扫描哪些包(使用SpringBootApplication注释中的scanbaseppackages属性)。

最新更新