AnnotationCommandHandlerAdapter invokes proxy which lost references to it's fields #277

Open
bilak opened this Issue Feb 13, 2017 · 3 comments

Projects

None yet

2 participants

@bilak
bilak commented Feb 13, 2017

Hello,
Using this sample project I'd like to setup axon without event sourcing. Just want to have command/event handling of axon. When I register AnnotationCommandHandlerAdapter for my command handler, it turns out that handling method is invoked on proxy which doesn't have references to it's (constructor) injected fields. Handling method then results to Command 'com.github.bilak.axon.domain.command.CreateTodoCommand' resulted in java.lang.NullPointerException(null).
If this doesn't have to do anything with axon, let me know and I will post the issue in spring.

PS: could there be any example of axon configuration without event sourcing?

@abuijze
Member
abuijze commented Feb 17, 2017

you shouldn't have to work with AnnotationCommandHandlerAdapters yourself. The Spring Support for Axon will automatically detect @CommandHandler annotated methods on beans and register it with the command bus. That might resolve the NPE as well.

Regarding non-eventsourcing, all you need to do is register a Repository for your Command Model (e.g. a GenericJpaRepository) and make sure your Aggregate is properly annotated with the required JPA Annotations. You can publish events using apply() (same method when using Event Sourcing) or by passing the EventBus as a parameter to your @CommandHandler methods and dispatching Events directly to the bus.

@bilak
bilak commented Feb 17, 2017

Hi @abuijze what am I then doing wrong? I've updated the sample and reconfigured repository to use GenericJpaRepository. Problem is that when commandGateway.send(...) is invoked I always get exception org.axonframework.commandhandling.NoHandlerForCommandException: No handler was subscribed to command [com.github.bilak.axon.domain.command.CreateTodoCommand]. Can you please look in updated sample and tell me if I've missconfigured something? thanks

Is it possible to delete aggregate (completely remove from store) using Axon's repositories when not using ES? When using ES one can use markDeleted() method which will mark aggregate as deleted. Can I use this method to remove not ES aggregate?

@abuijze
Member
abuijze commented Feb 20, 2017 edited

Your sample doesn't have any annotation on the Aggregate Root telling Axon to treat it as such. For Axon, your TodoEntity is just a class, like anything else.
Since you're using Boot, annotate it with @Aggregate(repository="todoRepository"). That will set up the necessary command handling components for aggregates.

And yes, you can use markDeleted in non-eventsourced aggregates. It will hint the repository that the entity should be removed from the underlying storage, instead of updated.

Finally, the exception also occurs because your commands are sent too early. The Initializer bean is not guaranteed to run after the command handlers have been registered. Instead of using @PostConstruct, try to hook into Spring's Lifecycle and send the commands when the context has been completely set up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment