You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "mdjava (via GitHub)" <gi...@apache.org> on 2024/07/30 07:37:29 UTC

[I] RocketMQMessageListenerBeanPostProcessor implements SmartLifecycle start() [rocketmq-spring]

mdjava opened a new issue, #672:
URL: https://github.com/apache/rocketmq-spring/issues/672

   @Override
       public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
       	 Class<?> targetClass = AopUtils.getTargetClass(bean);
            RocketMQMessageListener ann = targetClass.getAnnotation(RocketMQMessageListener.class);
            if (ann != null) {
                RocketMQMessageListener enhance = enhance(targetClass, ann);
                if (listenerContainerRegistrar != null) {
               	 log.warn("=== 111 ====");
                    listenerContainerRegistrar.registerContainer(beanName, bean, enhance);
                }
            }
           return bean;
       }
   
       @Override
       public int getPhase() {
           return Integer.MAX_VALUE - 2000;
       }
   
       @Override
       public void start() {
           if (!isRunning()) {
               this.setRunning(true);
               log.warn("=== 222 ====");
               listenerContainerRegistrar.startContainer();
           }
       }
   1、单独使用spring-boot 2.7.18  registerContainer start 顺序正确可正常使用。
   执行顺序 
   === 111 ==== 先执行
   === 222 ==== 后执行
   registerContainer 注册正常。
   start 正常。
   2、主要依赖如下
   spring-cloud  2021.0.6
   spring-cloud-starter-alibaba 2021.0.6.1
   spring-boot 2.7.18
   执行顺序 
   === 222 ==== 先执行
   === 111 ====  后执行
   registerContainer 注册正常。
   start 未能正常执行。
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] RocketMQMessageListenerBeanPostProcessor implements SmartLifecycle start() [rocketmq-spring]

Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on issue #672:
URL: https://github.com/apache/rocketmq-spring/issues/672#issuecomment-5223768432

   **Issue Evaluation**
   
   Category: `type/bug` | Status: **Confirmed**
   
   `RocketMQMessageListenerBeanPostProcessor` implementing `SmartLifecycle` and calling `start()` can cause issues with Spring's bean initialization ordering. The `BeanPostProcessor` interface is meant for bean post-processing during context refresh, not for lifecycle management.
   
   **Root Cause:** Mixing `BeanPostProcessor` and `SmartLifecycle` responsibilities in the same class can lead to premature initialization or circular dependency issues.
   **Impact:** Potential startup failures or unexpected behavior in complex Spring applications.
   **Severity:** medium — affects applications with specific bean initialization patterns.
   
   A fix should separate the lifecycle management from the bean post-processing logic.
   
   ---
   *Automated evaluation by RockteMQ-AI*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org