Can wrap Axon Annotations

I want to wrap Axon annotations like org.axonframework.commandhandling.CommandHandler like “com.my.commadnhandling.CommandHandler” so I can do any upgrades without changing existing codes.

Hi Kasun,

If you’d annotated your com.my.commandhandling.CommandHandler annotation file with Axon’s @CommandHandler annotation, you should be good.

Cheers,

Steven

Hi,

I did like this but it didnt work,


@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.ANNOTATION_TYPE})
@org.axonframework.commandhandling.CommandHandler
public @interface CommandHandler {

Which Axon version are you on?

If I do this, it just works fine:

@Target({ElementType.CONSTRUCTOR, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@CommandHandler
public @interface CustomCommandHandler {
}

Hi,
Its Axon 3.0.6.

I did exactly way you mentioned but didnt work, i got this error.

org.axonframework.commandhandling.NoHandlerForCommandException: No handler was subscribed to command [com.xxxx.yyy.order.command.CreateOrderCommand]

my command handler is like this,

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@org.axonframework.commandhandling.CommandHandler
public @interface MyCommandHandler {
}

The component that the @MyCommandHandler is on, is it annotated with @Aggregate (or @Component if a singleton bean)?

No, Its just a Class annotated with @Component.
I managed to get it work by doing this,

BaseCommandHandler {

    @org.axonframework.commandhandling.CommandHandler
    default void handle(BaseCqrsCommand command){}
}

And then,

@Component
public class OrderCommandHandler implements BaseCommandHandler {

    @Autowired
    private Repository<Order> orderRepository;

    @CommandHandler
    public void handle(final CreateOrderCommand command) throws Exception {
        orderRepository.newInstance(() -> new Order(command));
    }
}

It is required to add this method,

@org.axonframework.commandhandling.CommandHandler
    default void handle(BaseCqrsCommand command){}

it makes “org.axonframework.commandhandling.CommandHandler” visible(load to JVM ??) to axon framework. I think this is a workaround.

Hi Kasun,

I did a quick check (when I sent the previous email) and found an issue in the AnnotationCommandHandlerBeanPostProcessor. That issue (https://github.com/AxonFramework/AxonFramework/issues/615) has been fixed and will be included in 3.3.

Yes, having a single method annotated with @CommandHandler should work as a workaround, as it will trigger the BeanPostProcessor to consider that bean a Command Handler. The mechanism that inspects the actual hander mehtods actually does take meta annotations into account.

Cheers,

Allard

Hi Allard,

Thank you for your update. I’ll update the our framework to use Axon 3.3.Thanks.

Hi,

Can we wrap @SagaEventHandler annotations ?

Thanks.

Hi Kasun,

I’d make the exact same assumption Allard and I made around being able to wrap the @CommandHandler annotation in your own annotation for the @SagaEventHandler.

Best way to find out though, is to actually do it.

If you run in any issues as you did with the @CommandHandler, please keep us posted.

Maybe we can root out another issue we didn’t encounter yet.

Hope this helps!

Cheers,
Steven

Hi,

I created a custom Eventhandler like this,

public @interface SagaEventHandler {

    String associationProperty();

    String keyName() default "";

    Class<?> payloadType() default Object.class;

}

but i cannot annotate its using @org.axonframework.eventhandling.saga.SagaEventHandler because it is annotated as @Target(ElementType.METHOD) .
And I also annotated my custom SagaEventHandler like below, but it also didnt work,

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@EventHandler
public @interface SagaEventHandler {

Thanks,

Hi,

there is indeed an issue in some of the annotations. We have addressed those in the upcoming 3.3 release. We’re reviewing the last changes in that release and expect it to be available any time now.

Cheers,

Allard