Unit testing with AggregateTestFixture and @Autowired


I want to unit test my aggregate which has a bean with @Autowired.

I was able to do this with using @Autowired like this:

Hi Michael,

Your Aggregates are not Spring managed beans (not entirely at least).
As such, you should not have a global @Autowired service.
Instead you should only use the first option you’ve shared, thus having Axon resolve your service as a parameter.

Hope this helps you out Michael!



I learned to think about this in a following way. Axon cares about methods, but not about instances. Inside a method, a value can be injected as a parameter (exactly as you describe), but there is no “managed” bean instances.
In terms of scopes and lifecycle (e.g. prototypes in spring, of scope of CDI), there is no instance holding the state, managed by Axon…

I hope this helps.


Thanks a lot…