springboot整合rabbitmq與actuator出現bug
技術標籤:rabbitmqspringboot
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