SpringBoot循环依赖

问题描述

SpringBoot + Shiro + Swagger 配置完成,启动项目抛出如下错误信息:

Description:

The dependencies of some of the beans in the application context form a cycle:

   objectMapperConfigurer defined in class path resource [springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class]
      ↓
   authorizationAttributeSourceAdvisor defined in class path resource [org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfiguration.class]
┌─────┐
|  securityManager defined in class path resource [com/bbzd/mes/shiro/config/ShiroConfig.class]
↑     ↓
|  shiroFilterFactoryBean defined in class path resource [com/bbzd/mes/shiro/config/ShiroConfig.class]
└─────┘

原因

循环依赖其实就是循环引用,也就是两个或则两个以上的bean互相持有对方,最终形成闭环。比如A依赖于B,B依赖于C,C又依赖于A。如下图:
SpringBoot循环依赖_第1张图片

解决办法

找到重复,将@Bean 改为 @Autowired
SpringBoot循环依赖_第2张图片

你可能感兴趣的:(SpringBoot,SpringBoot,循环依赖)