Spring interdependence error: beancurrentyincreationexception unsatisfieddependencyexception

The project will generally start with an error reporting a certain bean loading error with the following key information.
org.springframework.beans.factory.UnsatisfiedDependencyException:Error creating bean with name ‘resUseTimeConfigController’: Unsatisfied dependency expressed through field ‘resUseTimeConfigService’; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name ‘resUseTimeConfigServiceImpl’: Bean with name ‘resUseTimeConfigServiceImpl’ has been injected into other beans [resUseTimeConfigSupport] 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.

The main reason is that the two beans depend on each other, the simplest solution is to add the @Lazy annotation, and then add the annotation under the @Autowired of the two classes.

 

//ClassB class is dependent on ClassA

@Autowired     

@Lazy//Annotate     

private ClassA classA; 


//ClassA class is dependent on ClassB

@Autowired     

@Lazy//Annotate    

private ClassB classB; 

Read More: