Announcement Announcement Module
Collapse
No announcement yet.
How to you solve a circular dependency in @Autowired Spring initialised services? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to you solve a circular dependency in @Autowired Spring initialised services?

    Can someone please let me know how to solve a circular dependency in @Autowired Spring initialised services?

    For example:

    class A {
    @Autowired
    B b;
    }


    class B {
    @Autowired
    C c;
    }

    class C {
    @Autowired
    A a;
    }

  • #2
    Can some one please respond... It's urgent

    Comment


    • #3
      Hi. jstrosh.
      I tried to produce error with above code, but I failed. I created following 3 classes A, B, C

      @Component
      class A {
      @Autowired
      B b;
      }

      @Component
      class B {
      @Autowired
      C c;
      }

      @Component
      class C {
      @Autowired()
      A a;
      }

      And tried to Autowire Class A into following Testcase class, then it succeeded.
      It was OK both version 3.1.0 and 2.5.6. Can you provide stacktrace?

      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration(locations="classpath:/test/context.xml")
      public class EmployeeDaoTest {

      @Autowired
      private A a;

      @Test
      public void test() {
      System.out.println(a);
      }
      }

      Comment

      Working...
      X