项目中出现了循环依赖问题:
1、排查了构造器注入
改成
2、yml中添加了允许循环依赖。
spring:
main:
allow-circular-references: true #允许循环引用
3、上面修改完之后还是不行
出现这个问题。
Requested bean is currently in creation: Is there an unresolvable circular reference?
Error creating bean with name 'ticketInterceptor': Unsatisfied dependency expressed through field 'appService';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appServiceImpl': Unsatisfied dependency expressed through field 'bizSysUserApi';
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'mvcResourceUrlProvider': Requested bean is currently in creation: Is there an unresolvable circular reference?
找到TicketInterceptor中AppService添加上@Lazy
@Lazy注解注解的作用主要是减少springIOC容器启动的加载时间。
Spring IoC (ApplicationContext) 容器一般都会在启动的时候实例化所有单实例 bean 。如果我们想要 Spring 在启动的时候延迟加载 bean,即在调用某个 bean 的时候再去初始化,那么就可以使用 @Lazy 注解。当出现循环依赖时,也可以添加@Lazy