Устранение неполадок RocketMQAutoConfiguration не загружен.

Spring Boot

задний план

Сегодня, после переноса параметров конфигурации проекта SpringBoot из исходного файла .yml в Apollo, при запуске сообщается об ошибке.

Bean method 'rocketMQTemplate' in 'RocketMQAutoConfiguration' not loaded because @ConditionalOnBean (types: org.apache.rocketmq.client.producer.DefaultMQProducer; SearchStrategy: all) did not find any beans of type org.apache.rocketmq.client.producer.DefaultMQProducer

Потребовалось два часа, чтобы окончательно разобраться, причина была в отсутствующем элементе конфигурацииspring.rocketmq.producer.groupВ результате невозможно успешно создать bean-компонент RocketMQAutoConfiguration, а ряд зависимых от него bean-компонентов не может быть успешно создан.

Процесс устранения неполадок

журнал ошибок запуска

2019-04-02 15:21:33.689  WARN 17516 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myServiceAImpl': Unsatisfied dependency expressed through field 'myServiceBImpl'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myServiceAImpl': Unsatisfied dependency expressed through field 'rocketMQTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.rocketmq.spring.starter.core.RocketMQTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2019-04-02 15:21:33.692  INFO 17516 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closed
2019-04-02 15:21:33.693  INFO 17516 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService
2019-04-02 15:21:33.693  INFO 17516 --- [           main] f.a.ReferenceAnnotationBeanPostProcessor : class com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor was destroying!
2019-04-02 15:21:33.702  INFO 17516 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-04-02 15:21:33.842 ERROR 17516 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field rocketMQTemplate in net.yourpackage.myServiceBImpl required a bean of type 'org.apache.rocketmq.spring.starter.core.RocketMQTemplate' that could not be found.
	- Bean method 'rocketMQTemplate' in 'RocketMQAutoConfiguration' not loaded because @ConditionalOnBean (types: org.apache.rocketmq.client.producer.DefaultMQProducer; SearchStrategy: all) did not find any beans of type org.apache.rocketmq.client.producer.DefaultMQProducer


Action:

Consider revisiting the conditions above or defining a bean of type 'org.apache.rocketmq.spring.starter.core.RocketMQTemplate' in your configuration.

проблема вызывает

DefaultMQProducer

Как видно из рисунка выше, метод mqProducer в RocketMQAutoConfiguration создаст DefaultMQProducer по параметрам конфигурации, из которых два обязательных параметра

  • spring.rocketmq.nameServer
  • spring.rocketmq.producer.group

Перепроверив конфигурационный файл, я обнаружил, что это действительно так, потому что spring.rocketmq.producer.group был опущен, после его добавления проект можно успешно запустить.