bug: circular reference creating RabbitHealthIndicator
使用@Autowire 注入 rabbitTemplate时出现
@kitonGao Unrelated, closed issues are not a good place to ask for some help. Both Stack Overflow and Gitter are better places to ask. With that said, your problem is that you are trying to autowire dependencies into the fields of the configuration class that defines those dependencies. As a result, when RabbitMqConfig tries to define your RabbitTemplate bean the connectionFactory field is null. You need to separate the definition and consumption of the beans. There are a few ways to do that including splitting things out into separate classes or injecting dependencies into the @Bean methods rather than the class’s fields. If you need any further pointers, please follow up on Stack Overflow or Gitter.
解决思路将其作为参数注入
但是在@PostConstrutor 不能有参数
最终方案
@Bean
ApplicationRunner rabbitRunner(RabbitTemplate rabbitTemplate) {
return args -> initRabbitTemplate(rabbitTemplate);
}
Reference:
https://github.com/spring-projects/spring-boot/issues/1081