在此步时做到 向容器手动注入Bean
实现 BeanDefinitionRegistryPostProcessor 接口
1.重写方法:
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
2.BeanDefinitionBuilder
BeanDefinitionBuilder mqBuilder = BeanDefinitionBuilder.genericBeanDefinition(RocketMQConsumer.class);
3.添加属性
mqBuilder.addConstructorArgValue(mqConsumerAnnotation.consumerGroup());
mqBuilder.addPropertyValue("mqCloudDomain", domainAddress);
4.注册
mqBuilder.setInitMethodName("start");
mqBuilder.setDestroyMethodName("shutdown");
registry.registerBeanDefinition(beanName + BEAN_FIX, mqBuilder.getBeanDefinition());
以下为Demo附上
标签:容器,BeanDefinitionBuilder,手动,Bean,实例,registry,mqBuilder From: https://www.cnblogs.com/zhaoyuxuan66/p/16617569.html