#456 Resolving a Circular Dependency in Spring

Companies:
Innotech
Themes:
SpringSpring CoreCode Review

Resolve the circular dependency problem:

@lombok.RequiredArgsConstructor
@org.springframework.stereotype.Controller
class LeController {

    private final AService a;

    @GetRequest("/")
    public String doGet() {
        a.foo2();
        return "ok";
    }
}

@lombok.RequiredArgsConstructor
@org.springframework.stereotype.Service
class AService {

    private final BService b;

    public void foo() {
        b.bar();
    }

    public void foo2() {
        // ...
    }
}

@lombok.RequiredArgsConstructor
@org.springframework.stereotype.Service
class BService {

    private final CService c;

    public void bar() {
        c.barK();
    }
}

@lombok.RequiredArgsConstructor
@org.springframework.stereotype.Service
class CService {

    private final AService a;

    public void barK() {
        a.foo2();
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in