Home > OS >  after upgrading the Spring boot version to 2.6, getting circular dependency error
after upgrading the Spring boot version to 2.6, getting circular dependency error

Time:10-12

Spring boot application failed to start after upgrading to 2.6.4 due to circular dependency.

I have two class like this:

class ABC{

    @Autowired
    PQR pqr;
}

Class PQR{

    @Autowired
    ABC abc;
}

previously working fine, now getting circular dependency error after upgrading spring boot to 2.6.4

How to resolve this?

CodePudding user response:

You can write @Lazy annotation at top of one of the autowire . This will let your spring application compile without any error

Like below:

Class PQR{
@Lazy
@Autowired
ABC abc;
}

CodePudding user response:

Go through this article once it might help https://www.baeldung.com/circular-dependencies-in-spring

  • Related