AbstractAnnotationHandlerBeanPostProcessor and Bean proxing


Axon with it’s Spring integration uses AbstractAnnotationHandlerBeanPostProcessor to process @EventHandler annotation.

But could someone explain why it is implemented as creating and especially replacing my bean with CGLIB-based proxy?


public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
    Class<?> targetClass = bean.getClass();
    final ClassLoader classLoader = targetClass.getClassLoader();
    if (parameterResolverFactory == null) {
        parameterResolverFactory = ClasspathParameterResolverFactory.forClassLoader(classLoader);
    if (isPostProcessingCandidate(targetClass)) {
        T adapter = initializeAdapterFor(bean, parameterResolverFactory);
        final I proxy = createAdapterProxy(bean, adapter, getAdapterInterface(), true, classLoader);
        managedAdapters.put(beanName, adapter);
        managedProxies.put(beanName, proxy);
        if (running) {
            subscribe(proxy, adapter);
        return proxy;


Wouldn’t it better just to create a separate Adapter Instance and subscribe it to EventBus not replacing bean itself?

And at least maybe it will be better just to return bean itself instead of proxy?

Thanks in advance.

Hi Nicolay,

we have dropped the proxy approach in Axon 3. In Axon 2, we used it to allow you to get the bean from the application context and simply cast it to an EventListeners. In later version of Axon 2, that approach wasn’t necessary anymore, as there were better alternatives. However, for backwards compatibility, we didn’t want to change the proxying approach.

Axon 3 will simply put an adapter in between the object and the invoker, so this is not an issue anymore.



Thank you!

So could you suggest how should I turn off proxying and switch to AnnotationEventListenerAdapter or any other alternatives?

With thanks,

Disabling it may open a whole different can of worms. It means you will have to register all your beans with the EventBus ‘manually’. Possible, but tedious work.
I’d migrate to Axon 3 sometime soon, instead.

I think that it is not very hard to iterate all beans in context and wrap them in AnnotationEventListenerAdapter. If there is no ‘standard’ I will do it by myself. Probably I will also try Axon 3.

Anyway, thank you!