Axon 2.1.2 and ParameterResolverFactory

Hey Allard,

I’m trying to take advantage of the ApplicationContextLookupParameterResolverFactory’s ability to detect beans of type ParameterResolverFactory. It seems to be picking them up okay, but because the ACLPRF isn’t the ParameterResolverFactory passed in to the AnnotationEvenListenerBeanPostProcessor, it’s not actually getting used.

Do I need to manually construct the ACLPRF (passing in the classpath resolver) as a Spring bean then pass that into the AELBPP, or is there a more automated way to do so?

JAmes

Hi James,

When using the axon:annotation-config/, the AnnotationEventListenerBeanPostProcessor (as well as the Command counterpart) are injected with the ACLPRF. If you “manually” configure the bean post processors, you need to pass in a ApplicationContextLookupParameterResolverFactory yourself.
(see https://github.com/AxonFramework/AxonFramework/blob/axon-2.1.2/core/src/main/java/org/axonframework/contextsupport/spring/AnnotationConfigurationBeanDefinitionParser.java#L83)

Cheers,

Allard

Ahh, okay. How evil is doing this?

p:parameterResolverFactory-ref="__axon-parameter-resolver-factory"

:slight_smile:

JAmes

You can easilly create another bean with your own name. It doesn’t have to be a ‘real’ singleton. At least, you won’t depend on the obscure name I chose for the ‘standard’ instance.

Evil is in the eye of the beholder. :wink:

Cheers,
Allard

Here’s what I ultimately came up with:

@Bean(name = “classpathParameterResolverFactory”)
public ParameterResolverFactory createClasspathParameterResolverFactory() {
return ClasspathParameterResolverFactory.forClassLoader(null);
}

and:









I also had to add @Priority(HIGH) to my ParameterResolverFactory, otherwise the FixtureResourceParameterResolverFactory was overriding it in tests.

Doing this is somewhat non-trivial (and I’m still not sure doing Priority(HIGH) is /right/, but it does work).

JAmes

Hi James,

why don’t you just do axon:annotation-config/ ?

Do you use the ApplicationContextLookupParameterResolverFactory in the test fixtures? Generally, the fixtures are meant to be lightweight. Just register your injectable parameters using the fixture. That doesn’t require the setup of an entire application context.

Looking at the fixtures, there is a little room for more customization of the parameter resolvers…

Cheers,

Allard

In our production Spring configuration, we have two instances of CommandBus. One is actually used to process commands, but another we call the “queryBus” where we route incoming requests to the read model. I believe at the time we had to drop the use of annotation-config as it was confused by having two CommandBus Spring beans in the application context.

JAmes

In the axon:annotation-config element, you can specify a command bus. In that case, all command handler beans will be registered with that command bus. Maybe that helps.

Cheers,

Allard