springboot project error org.springframework.beans.factory.UnsatisfiedDependencyException

springboot project error org.springframework.beans.factory.UnsatisfiedDependencyException

Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'analyzeController': Unsatisfied dependency expressed through field 'analyzeService'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'analyzeServiceImpl': Bean with name 'analyzeServiceImpl' has been injected into other beans [asyncServiceImpl] 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 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:397)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1429)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at com.yueshui.rsvrforecast.DemoApplication.main(DemoApplication.java:28)
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'analyzeServiceImpl': Bean with name 'analyzeServiceImpl' has been injected into other beans [asyncServiceImpl] 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 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:624)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:636)
	... 19 common frames omitted
	

The solution is to add @Lazy to see the annotation where this service is introduced. As shown below.

@Autowired
    private FloodRepository floodRepository;

    @Autowired
    private RainstormRepository rainstormRepository;

    @Autowired
    private ForecastService forecastService;

    @Lazy
    @Autowired
    private AnalyzeService analyzeService;

    @Autowired
    private LSFloodService lSFloodService;

    @Autowired
    private TrackService trackService;

Many solutions on the Internet have never said to use @Lazy to solve this problem. Most of the Baidu searches say to check carefully which bean does not write @service nonsense.
In fact, the exception is translated into Chinese (translated by Baidu) to get the following content

应用程序运行失败
org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“analyzeController”的bean时出错:通过字段“analyzeService”表达的不满意依赖;嵌套异常是 org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名为 'analyzeServiceImpl' 的 bean 时出错:名为 'analyzeServiceImpl' 的 Bean 已作为循环引用的一部分注入到其原始版本中的其他 bean [asyncServiceImpl] 中,但是最终被包裹。这意味着所述其他 bean 不使用该 bean 的最终版本。这通常是过于急切的类型匹配的结果 - 例如,考虑使用 'getBeanNamesOfType' 并关闭 'allowEagerInit' 标志。
在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
在 org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116)
在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:397)
在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1429)
在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
在 org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
在 com.yueshui.rsvrforecast.DemoApplication.main(DemoApplication.java:28)
引起:org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名为“analyzeServiceImpl”的bean时出错:名为“analyzeServiceImpl”的bean已作为循环引用的一部分注入到其原始版本中的其他bean [asyncServiceImpl]中,但已注入最终被包裹。这意味着所述其他 bean 不使用该 bean 的最终版本。这通常是过于急切的类型匹配的结果 - 例如,考虑使用 'getBeanNamesOfType' 并关闭 'allowEagerInit' 标志。
在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:624)
在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
在 org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
在 org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287)
在 org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:636)
... 省略了 19 个常用帧

Through the few Chinese sentences translated above, you can probably know the reason, that is, this bean is dependent on each other, other classes refer to this bean, and the references below this bean indirectly refer to other beans.
When you know the reason, there are many solutions. @Lazy is just a solution. You can also try the sentence mentioned in the above translation, and then Baidu will find out how to realize this solution.

Consider using 'getBeanNamesOfType' and turning off the 'allowEagerInit' flag.

Guess you like

Origin blog.csdn.net/weixin_44756075/article/details/118481560