java.lang.IllegalStateException: Failed to load ApplicationContext

Spring JIRA | Christopher Smith | 2 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    I have the following configuration class, with a nested extension: {code} @Configuration @Import(GalleryMockMvcConfig.InMemorySecurity) @CompileStatic class MockMvcMyConfig { @Bean MyHtmlController myHtmlController(WorkImageRepository images) { new MyHtmlController(images) } @Configuration @Import(MockMvcMyConfig) @CompileStatic static class Digitizer { @Bean DigitizerClientHtmlController digitizerClientHtmlController(PersonRepository people, UploadPermissionRepository permissions, UserOperations userOps) { new DigitizerClientHtmlController(people, permissions, userOps) } } } {code} {{GalleryMockMvcConfig.InMemorySecurity}} does not include {{Digitizer}}. When trying to use this class in {{@ContextConfiguration}}, I get the following exception: {code} java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:94) at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72) at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:170) at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:110) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212) at org.spockframework.spring.SpringTestContextManager.prepareTestInstance(SpringTestContextManager.java:49) at org.spockframework.spring.SpringInterceptor.interceptSetupMethod(SpringInterceptor.java:42) at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:28) at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87) at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88) at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55) at org.spockframework.runtime.extension.builtin.TestRuleInterceptor.intercept(TestRuleInterceptor.java:38) at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: A circular @Import has been detected: Illegal attempt by @Configuration class 'MockMvcMyConfig.Digitizer' to import class 'MockMvcMyConfig.Digitizer' as 'MockMvcMyConfig.Digitizer' is already present in the current import stack [ImportStack: [MockMvcMyConfig.Digitizer]] Offending resource: com.artsquare.gallery.web.html.mockmvc.config.MockMvcMyConfig$Digitizer at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70) at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:450) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:275) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:229) at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:317) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:246) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:229) at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:485) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:275) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:229) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:196) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:165) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:306) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:133) at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:60) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261) at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68) at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86) ... 19 more {code}

    Spring JIRA | 2 years ago | Christopher Smith
    java.lang.IllegalStateException: Failed to load ApplicationContext
  2. 0

    I have the following configuration class, with a nested extension: {code} @Configuration @Import(GalleryMockMvcConfig.InMemorySecurity) @CompileStatic class MockMvcMyConfig { @Bean MyHtmlController myHtmlController(WorkImageRepository images) { new MyHtmlController(images) } @Configuration @Import(MockMvcMyConfig) @CompileStatic static class Digitizer { @Bean DigitizerClientHtmlController digitizerClientHtmlController(PersonRepository people, UploadPermissionRepository permissions, UserOperations userOps) { new DigitizerClientHtmlController(people, permissions, userOps) } } } {code} {{GalleryMockMvcConfig.InMemorySecurity}} does not include {{Digitizer}}. When trying to use this class in {{@ContextConfiguration}}, I get the following exception: {code} java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:94) at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72) at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:170) at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:110) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212) at org.spockframework.spring.SpringTestContextManager.prepareTestInstance(SpringTestContextManager.java:49) at org.spockframework.spring.SpringInterceptor.interceptSetupMethod(SpringInterceptor.java:42) at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:28) at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87) at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88) at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55) at org.spockframework.runtime.extension.builtin.TestRuleInterceptor.intercept(TestRuleInterceptor.java:38) at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: A circular @Import has been detected: Illegal attempt by @Configuration class 'MockMvcMyConfig.Digitizer' to import class 'MockMvcMyConfig.Digitizer' as 'MockMvcMyConfig.Digitizer' is already present in the current import stack [ImportStack: [MockMvcMyConfig.Digitizer]] Offending resource: com.artsquare.gallery.web.html.mockmvc.config.MockMvcMyConfig$Digitizer at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70) at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:450) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:275) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:229) at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:317) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:246) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:229) at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:485) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:275) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:229) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:196) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:165) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:306) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:133) at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:60) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261) at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68) at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86) ... 19 more {code}

    Spring JIRA | 2 years ago | Christopher Smith
    java.lang.IllegalStateException: Failed to load ApplicationContext
  3. 0

    Spock-spring configuration class

    Google Groups | 4 years ago | Zachary Carter
    java.lang.IllegalStateException: Failed to load ApplicationContext
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Spring boot and Spock integration test

    Stack Overflow | 2 years ago | Sankaran PV
    java.lang.IllegalStateException: The WebApplicationContext for test context [TestContext@21a722ef testClass = HelloControllerSpec, testInstance = com.hello.HelloControllerSpec@63e68a2b, testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@3479404a testClass = HelloControllerSpec, locations = '{}', classes = '{class com.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.SpringApplicationContextLoader', parent = [null]]] must be configured with a MockServletContext.
  6. 0

    Spring XML configuration, default-lazy-init and spring properties not working

    Stack Overflow | 3 years ago | Jan
    java.lang.IllegalStateException: Failed to load ApplicationContext

    2 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Failed to load ApplicationContext

      at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext()
    2. Spring TestContext
      TestContextManager.prepareTestInstance
      1. org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:94)
      2. org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72)
      3. org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:170)
      4. org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:110)
      5. org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)
      5 frames
    3. org.spockframework.spring
      SpringInterceptor.interceptSetupMethod
      1. org.spockframework.spring.SpringTestContextManager.prepareTestInstance(SpringTestContextManager.java:49)
      2. org.spockframework.spring.SpringInterceptor.interceptSetupMethod(SpringInterceptor.java:42)
      2 frames
    4. Spock Framework - Core Module
      AbstractRuleInterceptor$1.evaluate
      1. org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:28)
      2. org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
      3. org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
      4. org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
      4 frames
    5. JUnit
      TestWatcher$1.evaluate
      1. org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
      1 frame
    6. Spock Framework - Core Module
      MethodInvocation.proceed
      1. org.spockframework.runtime.extension.builtin.TestRuleInterceptor.intercept(TestRuleInterceptor.java:38)
      2. org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
      2 frames
    7. JUnit4 Runner
      JUnit4TestReference.run
      1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      1 frame
    8. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      5 frames