@Service
public class A implements ServiceA {
@Autowired
private ServiceB b;
}
@Service
public class B implements ServiceB {
@Autowired
private ServiceC c;
}
@Repository
public class C implements ServiceC {
@Autowired
private ServiceA a;
}
When start the application, it will throw the Exception like this "org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name.......org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'ServiceC': Bean with name 'ServiceC' has been injected into other beans ...in its raw version as part of a circular reference, but has eventually been wrapped.".
I know we can use @Lazy or other methods to solve the Exception, but, when I only changed class C's annotation @Repository to @Service, the application starts normally without Exceptions. This confused me, why the application don't throw UnsatisfiedDependencyException? Whats the differences between @Service and @Repository?
ps. I have read some materials like this What's the difference between @Component, @Repository & @Service annotations in Spring?