Skip to main content

Posts

Showing posts from May, 2016

Spring circular dependency solution

I would like to suggest a solution of Dependency Injection which will be as much loyal as possible to the Spring IoC way and will help to overcome the circular dependency error. This means that we will have a single class that will have a reference to all the classes which need to be injected and will be responsible for the injection. I'll try to walk you through the steps. Assuming we have the following service classes which cause the circular error: @Service public class ServiceA{ @Autowire ServiceB serviceB; @Autowire ServiceC serviceC; } @Service public class ServiceB{ @Autowire ServiceA serviceA; @Autowire ServiceC serviceC; }                                               First step is to remove the @Autowire annotations, so we will move the wiring responsibility out of Spring hands. Second step is to create a class which will hold a reference to all the classe...