Resolução de dependência circular do Spring, resolução de dependência circular do Springboot

  ================================

©Copyright Sweet Potato Yao 2022-04-06

Blog da batata doce Yao - CSDN Blog

1. Descrição do problema

Bean com o nome 'xxx' foi injetado em outros beans [xxx] em sua versão bruta como parte de uma referência circular, mas acabou sendo encapsulado. Isso significa que os outros beans não usam a versão final do bean. Isso geralmente é o resultado de uma correspondência de tipo exagerada - considere usar 'getBeanNamesForType' com o sinalizador 'allowEagerInit' desativado, por exemplo.

Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sysUserServiceImpl': Bean with name 'sysUserServiceImpl' has been injected into other beans [sysAuthorityServiceImpl] 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, for example.
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:649)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:544)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:520)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:673)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:228)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:329)
	... 22 common frames omitted

2. Soluções

Adicione a anotação @Lazy a referências com dependências circulares

@Resource
@Lazy
private SysUserService sysUserService;

 (O tempo é precioso, compartilhar não é fácil, doe e retribua, ^_^)

 ================================

©Copyright Sweet Potato Yao 2022-04-06

Blog do Yao Batata Doce - Blog CSDN

 

Acho que você gosta

Origin blog.csdn.net/w995223851/article/details/123983993
Recomendado
Clasificación