Axon framework integration with aspectJ

Hi, I want to use aspectJ annotation’s with axon framework, any idea how can i achieve this.
Thanks,

I don’t think using AspectJ is any different in Axon than with any other type of application.
Do you have any specific problems?

Cheers,

Allard

I’m having a difficult time with simple advices for methods in the aggregate. I suspect it’s because a lot of interaction with an aggregate is through reflection.

For instance, with a simple TodoItem like this:

public class TodoItem extends AbstractAnnotatedAggregateRoot {

    @AggregateIdentifier
    private String id;

    public TodoItem() {
    }

    @CommandHandler
    public void markAsCompleted(MarkAsCompletedCommand command) {
        apply(new TodoItemCompletedEvent(command.getTodoId()));
    }

    @EventSourcingHandler
    public void on(TodoItemCreatedEvent event) {
        id = event.getTodoId();
    }

}

And an aspect like so:

public aspect TodoAspect {
    before(): call(void TodoItem.*()) {
        System.out.println("a command has been called");
    }
}

Yields no results from the TodoAspect. I removed the inheritance of AbstractAnnotatedAggregateRoot from TodoItem and the pointcuts are active.

Am I missing something or is there an alternative?

Thanks

Hi,

I see you’re doing a before:call() pointcut. Since the methods are (indeed) invoked through reflection, this pointcut might (my AOP/aspectJ experience is a bit outdated) not evaluate. However, using a before: execution() pointcut should still work.

Cheers,

Allard

Akonwi,

I think you pointcut syntax doe not match any method: try this. (double dot matches any number of method arguments)

before(): call(void TodoItem.*(..)) {
        System.out.println("a command has been called");
}

Cheers,
Benoit