I noticed that I made a circular dependency injection. The weird thing is I did not get any errors at runtime. But when I'm debugging the code I see that there is an infinite injection.
Let me quote interfaces and their implementations.
public interface AService {
//methods here
}
..
public interface BService {
//methods here
}
..
@Service
class AServiceImpl implements AService {
@Autowired
private BService bService;
}
..
@Service
class BServiceImpl implements BService {
@Autowired
private XService xService;
}
..
@Service
class XService {
@Autowired
private AService aService;
}
As you see above; AService -> BService -> XService -> AService
I did not get any circular dependency exception during run time. But when I put watchpoint on AService in XService I see that there is an infinite loop between above flow.
When I see that I categorized this as a bad design. With using @Lazy
annotation it's fixed but anyway I did not understand how I don't get circular dependency injection exception. Is it because I'm using interfaces and hiding implementations?
Thank you.