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']

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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}
    via by Janne Valkealahti,
  • 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}
    via by Janne Valkealahti,
  • 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}}?
    via by Jani,
    • 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)

    Users with the same issue

    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,