Hi Altug, Jan,
Axon Framework works with ParameterResolvers to resolve parameters for you message handling functions (like @EventHandler and @CommandHandler annotated functions).
Additionally, it contains a SpringBeanParameterResolver, which thus wires a Spring Bean into your command/event/query handler directly.
This is typically the way to go to wire a service into your Aggregate.
Wiring it through the @Autowired annotation as you’ve done Altug is at this point not completely supported.
I believe it has something to do in combination with Event Sourcing (obviously guessing you’re doing Event Sourcing), as the
EventSourcingRepository will recreate an Aggregate based on the events stored, without doing any Spring specific autowiring.
So, rather than having the
@Autowired lateinit var passwordEncoder: PasswordEncoder, you can put that service directly in your Command/Event handling function as another parameter.
For testing, Jan his suggestion is definitely correct.
you need to register that service as a resource to the Test Fixture.
Otherwise it will not be wired for you.
Hope this helps!