spring injection with @EventSourcingHandler seems not working

538 views
Skip to first unread message

ray.c...@gmail.com

unread,
Apr 10, 2017, 7:53:33 PM4/10/17
to Axon Framework Users
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

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

Axon 3.0.3

Best regards
Lei JIANG

ray.c...@gmail.com

unread,
Apr 10, 2017, 8:58:19 PM4/10/17
to Axon Framework Users

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

Steven van Beelen

unread,
Apr 11, 2017, 6:49:17 AM4/11/17
to axonfr...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Allard Buijze

unread,
Apr 11, 2017, 8:58:54 AM4/11/17
to axonfr...@googlegroups.com
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

To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.

ray.c...@gmail.com

unread,
Jul 22, 2017, 5:02:53 PM7/22/17
to Axon Framework Users
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

Allard Buijze

unread,
Jul 23, 2017, 1:09:55 AM7/23/17
to Axon Framework Users
Hi,

yes, this is indeed the way to do it.

Cheers,

Allard
Reply all
Reply to author
Forward
0 new messages