You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The SpringApplicationContextLoader assumes that the application is either using 100% XML or 100% Java config. This is because @ContextConfiguration allows either a list of classes or locations/value, not both. If any is specified, SpringApplicationContextLoader ignores the Application class that creates and starts the SpringApplication.
Trying to make Boot work with a 100% Groovy/no-XML pet project, I ran across the above issue. My Application class has @EnableAutoConfiguration and @componentscan annotations on it, the former required by Boot to set up a Web server. The later I had to keep because of SPR-11627. On the other hand, if I omitted the locations/value on @ContextConfiguration, dependencies weren't set up (duh!).
I give the code below along with a patch that I locally made to SpringApplicationContextLoader. I intend to send a pull request for this fix.
privateSet<Object> getSources(MergedContextConfigurationmergedConfig) {
Set<Object> sources = newLinkedHashSet<Object>();
sources.addAll(Arrays.asList(mergedConfig.getClasses()));
sources.addAll(Arrays.asList(mergedConfig.getLocations()));
/* The Spring application class may have annotations on it too. If such a class is declared on the test class, * add it as a source too. */SpringApplicationConfigurationspringAppConfig = AnnotationUtils.findAnnotation(mergedConfig.getTestClass(),
SpringApplicationConfiguration.class);
if (springAppConfig != null) {
sources.addAll(Arrays.asList(springAppConfig.classes()));
}
if (sources.isEmpty()) {
thrownewIllegalStateException(
"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() + ").");
}
returnsources;
}
The text was updated successfully, but these errors were encountered:
The following comments have been copied from SPR-11627.
I see several issues with your configuration.
Declaring both @ContextConfiguration and @SpringApplicationConfiguration directly on a test class is not supported. The first instance of @ContextConfiguration that is discovered for a given test class (either on a class in the test class hierarchy or as a meta-annotation) will be used. All others will be ignored.
Note that @SpringApplicationConfiguration is itself meta-annotated with @ContextConfiguration. Therefore, the declaration of @SpringApplicationConfiguration must be sufficient on its own.
Declaring both classes and locations/value for @ContextConfiguration is not supported (at least not in the Spring TestContext Framework in Core Spring). You are only allowed to declare one or the other. See the "Testing" chapter of the reference manual for the Spring Framework as well as the Javadoc for @ContextConfiguration for details.
In general, you need to select "one entry point" into your configuration. This is how production code works, and this is how test code works. You can always import other styles. For example, JavaConfig can import XML; XML can import JavaConfig; Groovy can import XML; etc.
The SpringApplicationContextLoader assumes that the application is either using 100% XML or 100% Java config. This is because @ContextConfiguration allows either a list of classes or locations/value, not both. If any is specified, SpringApplicationContextLoader ignores the Application class that creates and starts the SpringApplication.
Trying to make Boot work with a 100% Groovy/no-XML pet project, I ran across the above issue. My Application class has @EnableAutoConfiguration and @componentscan annotations on it, the former required by Boot to set up a Web server. The later I had to keep because of SPR-11627. On the other hand, if I omitted the locations/value on @ContextConfiguration, dependencies weren't set up (duh!).
I give the code below along with a patch that I locally made to SpringApplicationContextLoader. I intend to send a pull request for this fix.
MovieDatabaseRESTClientIntegrationTest.groovy
MovieDatabaseApplication.groovy
SpringApplicationContextLoader.java local fix
The text was updated successfully, but these errors were encountered: