update 1.7.22 connect and disconnect events cannot be accessed by aop

Author: wf-zyCreated Nov 7, 2022Updated Jun 26, 2025

I added a custom annotation to the connect event to intercept it, but it did not take effect, which is normal in 1.7.19,Check code found 1.7.22 SpringAnnotationScanner postProcessAfterInitialization and postProcessBeforeInitialization method has made the changes, Is this a bug?

 @OnConnect
  // customer annotation
  @EventCallbackAnnotation(eventName = "connect")
    public void connect(SocketIOClient client) throws InterruptedException {
        log.info("有新客户端连接sessionId:{}", client.getSessionId().toString());
    }
1.7.22 SpringAnnotationScanner class
  public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (this.originalBeanClass != null) {
            this.socketIOServer.addListeners(this.originalBean, this.originalBeanClass);
            log.info("{} bean listeners added", this.originalBeanName);
            this.originalBeanClass = null;
            this.originalBeanName = null;
        }

        return bean;
    }

    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        final AtomicBoolean add = new AtomicBoolean();
        ReflectionUtils.doWithMethods(bean.getClass(), new MethodCallback() {
            public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
                add.set(true);
            }
        }, new MethodFilter() {
            public boolean matches(Method method) {
                Iterator var2 = SpringAnnotationScanner.this.annotations.iterator();

                Class annotationClass;
                do {
                    if (!var2.hasNext()) {
                        return false;
                    }

                    annotationClass = (Class)var2.next();
                } while(!method.isAnnotationPresent(annotationClass));

                return true;
            }
        });
        if (add.get()) {
            this.originalBeanClass = bean.getClass();
            this.originalBean = bean;
            this.originalBeanName = beanName;
        }

        return bean;
    }

this.originalBean storage is the original Object, postProcessAfterInitialization (Object beans, String beanName) USES the bean originalBean without using a proxy Object, Disabling aop

1.7.19 version is normal

 @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (originalBeanClass != null) {
            socketIOServer.addListeners(bean, originalBeanClass);
            log.info("{} bean listeners added", beanName);
            originalBeanClass = null;
        }
        return bean;
    }