java.lang.IllegalStateException: Neither YarnClusterInjectingXmlContextLoader nor YarnClusterInjectingAnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@2eedd06a declaringClass = 'org.springframework.yarn.test.context.YarnClusterInjectingMiniYarnClusterTestContextLoaderTests', locations = '{}', classes = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.yarn.test.context.YarnDelegatingSmartContextLoader']

Spring JIRA | Janne Valkealahti | 3 years ago
  1. 0

    I have below classes in my tests. This used to work with 4.0.2 but now fails with 4.0.3. I don't know if this is somehow related to work for SPR-11455 and other jira's linked to it. [ComposedAnnotationTests.java|https://github.com/spring-projects/spring-hadoop/blob/master/spring-yarn/spring-yarn-test/src/test/java/org/springframework/yarn/test/context/ComposedAnnotationTests.java] {code} @RunWith(SpringJUnit4ClassRunner.class) @CustomMiniYarnClusterTest public class ComposedAnnotationTests { @Autowired private ApplicationContext ctx; @Resource(name = "yarnConfiguration") Configuration configuration; @Test public void testLoaderAndConfig() { assertNotNull(ctx); assertTrue(ctx.containsBean("yarnCluster")); assertTrue(ctx.containsBean("yarnConfiguration")); assertTrue(ctx.containsBean("myCustomBean")); Configuration config = (Configuration) ctx.getBean("yarnConfiguration"); assertNotNull(config); } } {code} [CustomMiniYarnClusterTest|https://github.com/spring-projects/spring-hadoop/blob/master/spring-yarn/spring-yarn-test/src/test/java/org/springframework/yarn/test/context/CustomMiniYarnClusterTest.java] {code} @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @ContextConfiguration(loader=YarnDelegatingSmartContextLoader.class) @MiniYarnCluster public @interface CustomMiniYarnClusterTest { @Configuration public static class Config { @Bean public String myCustomBean() { return "myCustomBean"; } } } {code} This fails with message: {noformat} java.lang.IllegalStateException: Neither YarnClusterInjectingXmlContextLoader nor YarnClusterInjectingAnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@2eedd06a declaringClass = 'org.springframework.yarn.test.context.YarnClusterInjectingMiniYarnClusterTestContextLoaderTests', locations = '{}', classes = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.yarn.test.context.YarnDelegatingSmartContextLoader'] at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.processContextConfiguration(AbstractDelegatingSmartContextLoader.java:200) at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:703) at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:656) at org.springframework.test.context.DefaultTestContext.<init>(DefaultTestContext.java:93) at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:119) {noformat}

    Spring JIRA | 3 years ago | Janne Valkealahti
    java.lang.IllegalStateException: Neither YarnClusterInjectingXmlContextLoader nor YarnClusterInjectingAnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@2eedd06a declaringClass = 'org.springframework.yarn.test.context.YarnClusterInjectingMiniYarnClusterTestContextLoaderTests', locations = '{}', classes = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.yarn.test.context.YarnDelegatingSmartContextLoader']
  2. 0

    I have below classes in my tests. This used to work with 4.0.2 but now fails with 4.0.3. I don't know if this is somehow related to work for SPR-11455 and other jira's linked to it. [ComposedAnnotationTests.java|https://github.com/spring-projects/spring-hadoop/blob/master/spring-yarn/spring-yarn-test/src/test/java/org/springframework/yarn/test/context/ComposedAnnotationTests.java] {code} @RunWith(SpringJUnit4ClassRunner.class) @CustomMiniYarnClusterTest public class ComposedAnnotationTests { @Autowired private ApplicationContext ctx; @Resource(name = "yarnConfiguration") Configuration configuration; @Test public void testLoaderAndConfig() { assertNotNull(ctx); assertTrue(ctx.containsBean("yarnCluster")); assertTrue(ctx.containsBean("yarnConfiguration")); assertTrue(ctx.containsBean("myCustomBean")); Configuration config = (Configuration) ctx.getBean("yarnConfiguration"); assertNotNull(config); } } {code} [CustomMiniYarnClusterTest|https://github.com/spring-projects/spring-hadoop/blob/master/spring-yarn/spring-yarn-test/src/test/java/org/springframework/yarn/test/context/CustomMiniYarnClusterTest.java] {code} @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @ContextConfiguration(loader=YarnDelegatingSmartContextLoader.class) @MiniYarnCluster public @interface CustomMiniYarnClusterTest { @Configuration public static class Config { @Bean public String myCustomBean() { return "myCustomBean"; } } } {code} This fails with message: {noformat} java.lang.IllegalStateException: Neither YarnClusterInjectingXmlContextLoader nor YarnClusterInjectingAnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@2eedd06a declaringClass = 'org.springframework.yarn.test.context.YarnClusterInjectingMiniYarnClusterTestContextLoaderTests', locations = '{}', classes = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.yarn.test.context.YarnDelegatingSmartContextLoader'] at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.processContextConfiguration(AbstractDelegatingSmartContextLoader.java:200) at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:703) at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:656) at org.springframework.test.context.DefaultTestContext.<init>(DefaultTestContext.java:93) at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:119) {noformat}

    Spring JIRA | 3 years ago | Janne Valkealahti
    java.lang.IllegalStateException: Neither YarnClusterInjectingXmlContextLoader nor YarnClusterInjectingAnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@2eedd06a declaringClass = 'org.springframework.yarn.test.context.YarnClusterInjectingMiniYarnClusterTestContextLoaderTests', locations = '{}', classes = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.yarn.test.context.YarnDelegatingSmartContextLoader']
  3. 0

    I'm trying to use {{CamelSpringDelegatingTestContextLoader}} with TestNG. Here's my test class: {code:title=MyTest.java|} @ContextConfiguration(classes = SpringTestConfiguration.class, loader = CamelSpringDelegatingTestContextLoader.class) public class MyTest extends AbstractCamelTestNGSpringContextTests { @Autowired private CamelContext camelContext; @Test public void test() { Assert.notNull(camelContext); } } {code} Configuration class: {code:title=SpringTestConfiguration.java} @Configuration @ComponentScan(basePackageClasses = {SpringTestRoot.class}) public class SpringTestConfiguration extends CamelConfiguration { } {code} Here's the exception I'm getting: {code} org.testng.TestNGException: Cannot instantiate class com.mycompany.demo.MyTest at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:38) at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:380) at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:293) at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:115) at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:200) at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:120) at org.testng.TestRunner.initMethods(TestRunner.java:409) at org.testng.TestRunner.init(TestRunner.java:235) at org.testng.TestRunner.init(TestRunner.java:205) at org.testng.TestRunner.<init>(TestRunner.java:160) at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:141) at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:271) at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:575) at org.testng.SuiteRunner.init(SuiteRunner.java:159) at org.testng.SuiteRunner.<init>(SuiteRunner.java:113) at org.testng.TestNG.createSuiteRunner(TestNG.java:1299) at org.testng.TestNG.createSuiteRunners(TestNG.java:1286) at org.testng.TestNG.runSuitesLocally(TestNG.java:1140) at org.testng.TestNG.run(TestNG.java:1057) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29) ... 27 more Caused by: java.lang.IllegalStateException: Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@327b636c declaringClass = 'org.apache.camel.testng.AbstractCamelTestNGSpringContextTests', classes = '{}', locations = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.apache.camel.testng.AbstractCamelTestNGSpringContextTests$TestNGCamelSpringTestContextLoader'] at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.processContextConfiguration(AbstractDelegatingSmartContextLoader.java:201) at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:607) at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:560) at org.springframework.test.context.TestContext.<init>(TestContext.java:99) at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:121) at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:107) at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.<init>(AbstractTestNGSpringContextTests.java:108) at org.apache.camel.testng.AbstractCamelTestNGSpringContextTests.<init>(AbstractCamelTestNGSpringContextTests.java:49) at com.mycompany.demo.MyTest.<init>(MyTest.java:12) ... 32 more {code} If I drop {{AbstractCamelTestNGSpringContextTests}} and use {{AbstractTestNGSpringContextTests}} and copy the listeners I'm able to execute the test. Will there be TestNG support for {{CamelSpringDelegatingTestContextLoader}}?

    Apache's JIRA Issue Tracker | 2 years ago | Jani
    com.mycompany.demo.MyTest
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Why I obtain this error message when I try to move the configuration class as an inner class of the test class?

    Stack Overflow | 2 years ago | AndreaNobili
    java.lang.IllegalStateException: Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@52d455b8 declaringClass = 'rewards.RewardNetworkTests', locations = '{}', classes = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.test.context.ContextLoader']
  6. 0

    Spring testing using @ContextConfiguration or @ContextHierarchy

    javarticles.com | 3 months ago
    java.lang.IllegalStateException: Configuration error: both default locations AND default configuration classes were detected for context configuration [ContextConfigurationAttributes@3f102e87 declaringClass = 'com.javarticles.spring.SpringFailureTest', classes = '{class com.javarticles.spring.SpringFailureTest$Config}', locations = '{classpath:com/javarticles/spring/SpringFailureTest-context.xml}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.test.context.ContextLoader']; configure one or the other, but not both.

    1 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

      Neither YarnClusterInjectingXmlContextLoader nor YarnClusterInjectingAnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@2eedd06a declaringClass = 'org.springframework.yarn.test.context.YarnClusterInjectingMiniYarnClusterTestContextLoaderTests', locations = '{}', classes = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.yarn.test.context.YarnDelegatingSmartContextLoader']

      at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.processContextConfiguration()
    2. Spring TestContext
      TestContextManager.<init>
      1. org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.processContextConfiguration(AbstractDelegatingSmartContextLoader.java:200)
      2. org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:703)
      3. org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:656)
      4. org.springframework.test.context.DefaultTestContext.<init>(DefaultTestContext.java:93)
      5. org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:119)
      5 frames