spring injection with @EventSourcingHandler seems not working

Hi Allard,

I try to inject a spring bean (JythonObjectFactory) as a parameter in @EventSourcingHandler, but I get error like “Caused by: org.axonframework.messaging.annotation.UnsupportedHandlerException: Unable to resolver parameter 1 (JythonObjectFactory) in handler”

@EventSourcingHandler
public void on(BusinessStreamStartingEvent event,
               JythonObjectFactory jythonObjectFactory;) {
  log.info("business stream starting event {} {}", event, jythonObjectFactory);
}

I found in forum that axon 2 had already similar issue, but not sure if it’s same one
https://axonframework.myjetbrains.com/youtrack/issue/AXON-265

PS : JythonObjectFactory class is a @Component, so is in the spring context.

Axon 3.0.3

Best regards
Lei JIANG

If I understood correctly, @EventSourcingHandler’s MultiParameterResolverFactory should use SpringBeanParameterResolverFactory for spring bean injection

Am I missing something in the configuration axon ?

Regards
Lei JIANG

Hi Lei,

I believe there was an issue in 3.0 that the SpringBeanParameterResolver wasn’t created for event handling/sourcing functions, but that should’ve been fixed some time ago.
For testing I just ran the axon-bank example on 3.0.3 and the SpringBeanParameterResolverFactory is part of the MultiParameterResolverFactory.
As far as my understanding goes, if you’re running a Spring application, the SpringParameterResolverFactoryBean should automatically create a SpringBeanParameterResolverFactory.

Could you verify the JythonObjectFactory can be autowired in to other places?

Hoping this helps,

Cheers,
Steven

Hi Lei,

from you screenshot, I conclude that there is no SpringParameterResolver in the list of resolvers. This would mean Spring bean injection isn’t supported in your setup.

Do you define any repositories yourself in the application context?

Allard

Hi Allard,

Yes, I defined repository with ehcache in my config without ParameterResolverFactory in the constructor param of my repository.
.
I just injected it (it should be defined already in axon config context) in my parameters like:

@Bean
public Repository<BusinessStreamRun> businessStreamRunRepository(AggregateFactory<BusinessStreamRun> businessStreamRunAggregateFactory, 
                                                                 EventStore eventStore,
                                                                 ParameterResolverFactory parameterResolverFactory,
                                                                 Cache businessStreamRunCache) {
  return new CachingEventSourcingRepository<>(businessStreamRunAggregateFactory,
                                              eventStore,
                                              new PessimisticLockFactory(),
                                              businessStreamRunCache,
                                              parameterResolverFactory,
                                              NoSnapshotTriggerDefinition.INSTANCE);
}

It seems working now, is that a good solution ?

Regards

Hi,

yes, this is indeed the way to do it.

Cheers,

Allard