diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java index 8d733904f3..e2d155e896 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java @@ -29,7 +29,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.context.web.ServletContextApplicationContextInitializer; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextInitializer; +import org.springframework.core.SpringVersion; import org.springframework.mock.web.MockServletContext; +import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextLoader; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.support.AbstractContextLoader; @@ -77,6 +79,16 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { return application.run(); } + @Override + public void processContextConfiguration( + ContextConfigurationAttributes configAttributes) { + if (!configAttributes.hasLocations() && !configAttributes.hasClasses()) { + Class[] defaultConfigClasses = detectDefaultConfigurationClasses(configAttributes + .getDeclaringClass()); + configAttributes.setClasses(defaultConfigClasses); + } + } + /** * Builds new {@link org.springframework.boot.SpringApplication} instance. You can * override this method to add custom behaviour @@ -92,8 +104,9 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { sources.addAll(Arrays.asList(mergedConfig.getLocations())); if (sources.isEmpty()) { throw new IllegalStateException( - "No configuration resources found (use classes= or locations= in @SpringApplicationConfiguration). " - + "Default configuration detection is not supported with this loader (see SPR-11455 for details)"); + "No configuration classes or locations found in @SpringApplicationConfiguration. " + + "For default configuration detection to work you need Spring 4.0.3 or better (found " + + SpringVersion.getVersion() + ")."); } return sources; } diff --git a/spring-boot/src/test/java/org/springframework/boot/AdhocTestSuite.java b/spring-boot/src/test/java/org/springframework/boot/AdhocTestSuite.java index 4889794ba2..5c595d3d76 100644 --- a/spring-boot/src/test/java/org/springframework/boot/AdhocTestSuite.java +++ b/spring-boot/src/test/java/org/springframework/boot/AdhocTestSuite.java @@ -16,7 +16,6 @@ package org.springframework.boot; -import org.junit.Ignore; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @@ -29,9 +28,9 @@ import org.springframework.boot.test.SpringApplicationConfigurationJmxTests; * @author Dave Syer */ @RunWith(Suite.class) -@SuiteClasses({ SpringApplicationConfigurationDefaultConfigurationTests.class, - SpringApplicationConfigurationJmxTests.class }) -@Ignore +@SuiteClasses({ SpringApplicationConfigurationJmxTests.class, + SpringApplicationConfigurationDefaultConfigurationTests.class }) +// @Ignore public class AdhocTestSuite { } diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java b/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java index 9daa7c1da4..d99eb179e3 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java @@ -33,7 +33,7 @@ import static org.junit.Assert.assertNotNull; */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration -@Ignore("Ignore until gh-380, SPR-11455 can be resolved") +@Ignore("Ignore until SPR-11455 is resolved (Spring 4.0.3)") public class SpringApplicationConfigurationDefaultConfigurationTests { @Autowired