Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'menuServiceImpl': Bean with name 'menuServiceImpl' has been injected into other beans [permissionServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off


当服务数量开始增加时,可能会发生循环依赖性,就可能发生循环依赖。

循环依赖关系将导致Spring Application Context失败,并且症状是一个错误:

名称为'*********'的Bean已被注入其他Bean [******,**********,**********, **********]的原始版本(作为循环引用的一部分),

但最终被包装(例如,作为自动代理创建的一部分)。 这意味着所说的其他bean不使用该bean的最终版本。 这通常是过度渴望类型匹配的结果–例如,考虑在关闭“ allowEagerInit”标志的情况下使用“ getBeanNamesOfType”。

解决方案:

1.@Lazy注解

2.bean配置xml配置default-lazy-init =“ true”

可行的解决方案是将default-lazy-init =“ true”添加到应用程序配置xml文件中:

<beans default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd >

<context:component-scan base-package="com.package">

</context:component-scan> <context:annotation-config/> ...


参考地址:https://blog.csdn.net/s674334235/article/details/107370478

https://www.cnblogs.com/nick-huang/p/13929455.html