I have a Spring MVC application which uses a dependency library which initialises some Beans lazily. But those lazy beans are required during startup for initialising some other Beans. So, when those lazy beans(‘db_client’ is one of them) are being initialised, the application startup fails by throwing below error
Error creating bean with name 'ServiceConfiguration': Unsatisfied dependency expressed through field 'myDatabase': Error creating bean with name 'db_client': Requested bean is currently in creation: Is there an unresolvable circular reference?
I went through the beans that are required for this and don’t see any circular dependency, atleast for the beans involved here. I suspected if something is going wrong when “db_client” bean was being initialised and found while debugging that there is a place where context.getBeansOfType(SomeObject.class)
was being called and this statement was throwing below error:
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@72bdd7c7 has not been refreshed yet
Unfortunately, the dependency where the lazy beans are being initialzed can’t be swapped with an alternative. What could be going wrong here and how can we fix this error?