在SpringBoot中使用Shiro发生循环依赖

问题

下图是控制台的报错信息,产生了循环依赖。
在这里插入图片描述

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

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]
┌─────┐
|  defaultWebSecurityManager defined in class path resource [com/zust/ysc/config/shiro/ShiroConfig.class]
↑     ↓
|  shiroFilterFactoryBean defined in class path resource [com/zust/ysc/config/shiro/ShiroConfig.class]
└─────┘


Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

原因

具体原因找了很久也没有找到,网上有一些解决方式,但都没有说原因,我也不浪费时间了。有些人提到了下面这两个依赖的问题,问题确实是在这里。我最初学Shiro是看的狂神的视频,他用的是第二个依赖,我自己实现时自作聪明换成了第一个,所以就报了上面的问题。这两个依赖去实现ShiroConfig类所要实现的方法是不一样的。比如第二个依赖需要实现ShiroFilterFactoryBean,而第一个不需要这个,而是ShiroFilterChainDefinition,具体可以去看官网,网上也有基于第一个依赖实现的方式。

<dependency>
	<groupId>org.apache.shiro</groupId>
	<artifactId>shiro-spring-boot-web-starter</artifactId>
	<version>1.6.0</version>
</dependency>

<dependency>
	<groupId>org.apache.shiro</groupId>
	<artifactId>shiro-spring</artifactId>
	<version>1.7.0</version>
</dependency>

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Fishermen_sail/article/details/129787493
今日推荐