Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘commonConvertServiceImpl’: Unsatisfied dependency expressed through field ‘****Service’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘****ServiceImpl’: Unsatisfied dependency expressed through field ‘****Service’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘****ServiceImpl’: Unsatisfied dependency expressed through field ‘iConvertService’; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name ‘****ServiceImpl’: Bean with name ‘***ertServiceImpl’ has been injected into other beans [***ServiceImpl,***ManagerServiceImpl] 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.annotation.AutowiredAnnotationBeanPostProcessor
A
u
t
o
w
i
r
e
d
F
i
e
l
d
E
l
e
m
e
n
t
.
i
n
j
e
c
t
(
A
u
t
o
w
i
r
e
d
A
n
n
o
t
a
t
i
o
n
B
e
a
n
P
o
s
t
P
r
o
c
e
s
s
o
r
.
j
a
v
a
:
643
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
b
e
a
n
s
.
f
a
c
t
o
r
y
.
a
n
n
o
t
a
t
i
o
n
.
I
n
j
e
c
t
i
o
n
M
e
t
a
d
a
t
a
.
i
n
j
e
c
t
(
I
n
j
e
c
t
i
o
n
M
e
t
a
d
a
t
a
.
j
a
v
a
:
119
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
b
e
a
n
s
.
f
a
c
t
o
r
y
.
a
n
n
o
t
a
t
i
o
n
.
A
u
t
o
w
i
r
e
d
A
n
n
o
t
a
t
i
o
n
B
e
a
n
P
o
s
t
P
r
o
c
e
s
s
o
r
.
p
o
s
t
P
r
o
c
e
s
s
P
r
o
p
e
r
t
i
e
s
(
A
u
t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AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1415) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda
AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1415)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531)atorg.springframework.beans.factory.support.AbstractBeanFactory.lambdadoGetBean
0
(
A
b
s
t
r
a
c
t
B
e
a
n
F
a
c
t
o
r
y
.
j
a
v
a
:
335
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
b
e
a
n
s
.
f
a
c
t
o
r
y
.
s
u
p
p
o
r
t
.
D
e
f
a
u
l
t
S
i
n
g
l
e
t
o
n
B
e
a
n
R
e
g
i
s
t
r
y
.
g
e
t
S
i
n
g
l
e
t
o
n
(
D
e
f
a
u
l
t
S
i
n
g
l
e
t
o
n
B
e
a
n
R
e
g
i
s
t
r
y
.
j
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
e
s
o
l
v
e
D
e
p
e
n
d
e
n
c
y
(
D
e
f
a
u
l
t
L
i
s
t
a
b
l
e
B
e
a
n
F
a
c
t
o
r
y
.
j
a
v
a
:
1287
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
b
e
a
n
s
.
f
a
c
t
o
r
y
.
a
n
n
o
t
a
t
i
o
n
.
A
u
t
o
w
i
r
e
d
A
n
n
o
t
a
t
i
o
n
B
e
a
n
P
o
s
t
P
r
o
c
e
s
s
o
r
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:1367) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1287) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
0(AbstractBeanFactory.java:335)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)atorg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1367)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1287)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessorAutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
… 57 common frames omitted
如上错误,我们可以看到主要问题是循环依赖导致项目产生错误。
也就是这个iConvertService
在@Autowired
修饰的下造成的循环依赖,我们可以用如下解决办法:
-
构造函数注入改为Setter方法注入:将循环依赖的类之间的构造函数注入改为Setter方法注入。这样可以打破循环依赖链条,使得Spring能够正确地解析依赖关系。
-
使用@Lazy注解延迟初始化:在循环依赖的其中一个类上使用@Lazy注解,将其标记为延迟初始化。这样Spring会在需要时才创建对象,从而避免循环依赖问题。
-
使用@DependsOn注解指定初始化顺序:使用@DependsOn注解来指定Bean的初始化顺序。通过在循环依赖的类上使用@DependsOn注解,可以明确指定它们之间的初始化顺序,从而解决循环依赖问题。
-
使用代理对象:在循环依赖的类中使用代理对象来解决循环依赖。Spring可以通过代理对象来解决循环依赖问题,从而保持依赖关系的正确性。
-
使用@Autowired注解指定特定的Bean名称:在循环依赖的类中使用@Autowired注解,并通过@Qualifier注解指定特定的Bean名称。这样可以明确指定依赖的Bean,从而解决循环依赖问题。
而我选择的办法则是:在造成循环依赖的类里边调用的iConvertService
接口上加上@Lazy。
@Autowired
@Lazy
private IConvertService iConvertService;
进而解决相关问题。