Gurkirat Singh Guliani
Gurkirat Singh Guliani

Reputation: 1015

EventHandler in external java file not getting triggered

I have an Aggregate class which has

  1. CommandHandler that receives a CreateAccountCommand

  2. 1 EventSourceHandling that receives AccountCreatedEvent

Correspondingly, in other package, I’ve @EventHandler for the AccountCreatedEvent. However, it is not getting invoked.

@Component
class EventHandlingComponent {

  @Autowired AccountRepository repo; 

  @EventHandler
  public void on(AccountCreatedEvent event ) 
  {
    // save to repository ; 
  }
}

I’m using spring boot application with this added as dependency

<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>

I'll be really thankful if someone can point me what mistake I'm making.

Upvotes: 0

Views: 668

Answers (1)

Marc Gathier
Marc Gathier

Reputation: 361

Is the event handler class in a package that is a subpackage from the package of the main class? If not, the scanner will not find the class by default. In this case you will have to configure which packages Spring boot should scan (using the scanBasePackages property in the SpringBootApplication annotation).

Upvotes: 1

Related Questions