项目正常启动没有问题
这是@Configuration下RabbitMQConfig
这是通过接口调用ac.refresh();
这是运行结果
到这里都是没有任何问题的,项目启动时RabbitMQConfig初始化正常,通过接口调用ac.refresh(),刷新容器重新初始化RabbitMQConfig正常
但是如果我在RabbitMQConfig使用@Autowired注入,项目启动时可以正常运行,但是调用ac.refresh()则会出错,提示无法注入
这是@Configuration下RabbitMQConfig
这是通过接口调用ac.refresh();
这是运行结果
发出告警
2019-07-27 11:40:36.521 WARN 7444 --- [nio-8120-exec-1] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rabbitMqConfig': Unsatisfied dependency expressed through field 'demoConfigurationService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demoConfigurationService': Unsatisfied dependency expressed through field 'dao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.pubinfo.modules.demo.dao.DemoConfigurationDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2019-07-27 11:40:36.586 WARN 7444 --- [nio-8120-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rabbitMqConfig': Unsatisfied dependency expressed through field 'demoConfigurationService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demoConfigurationService': Unsatisfied dependency expressed through field 'dao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.pubinfo.modules.demo.dao.DemoConfigurationDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}