Our application somehow gets into an unusable state very intermittently and in a hard to reproduce fashion. We found it follows a path that uses this code that we think is likely the cause of the issue but aren't sure why or how to fix it. We don't see this around specific if statements so it doesn't seem like it's going down a different path of code but rather more likely a timing issue.
`import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
((AnnotationConfigWebApplicationContext) applicationContext).refresh();`
It seems like the refresh triggers the following error so the next time we try and go through normal code paths spring is in a bad state.
`Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'MyCodeClass' defined in URL [jar:file:/path/repo-version.jar!/com/mypathtoMyCodeClassImpl.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.ProxyCachingConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available`
MyCodeClass semi looks like
`import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@Component("MyCodeClass")
public class MyCodeClassImpl implements MyCodeClass, AnotherInterface {
@Autowired
@Lazy
private ApplicationContext applicationContext;
... Other code
}`