Closed
Description
Rob Winch opened SPR-10660 and commented
@Enable
annotations have no meaning unless combined with @Configuration
. It would be useful to allow configurations with only @Enable
annotations.
It would be ideal if all the following tests pass (each test is marked with a comment with its current behavior):
package sample;
... imports omitted ...
public class EnableWithNoConfigurationAnnotationTests {
private ConfigurableApplicationContext context;
@After
public void closeContext() {
if(context != null) {
context.close();
}
}
// succeeds
@Test
public void enableWebMvcWithConfigurationAnnotation() {
assertLoadsWebMvc(EnableWebMvcWithConfigurationAnnotationConfig.class);
}
@EnableWebMvc
@Configuration
static class EnableWebMvcWithConfigurationAnnotationConfig {}
// fails
@Test
public void enableWebMvcNoConfigurationAnnotation() {
assertLoadsWebMvc(EnableWebMvcNoConfigurationAnnotationConfig.class);
}
@EnableWebMvc
static class EnableWebMvcNoConfigurationAnnotationConfig {}
// fails
@Test
public void enableWebMvcNoConfigurationClasspathScanning() {
assertLoadsWebMvc(EnableWebMvcWithClasspathScanningConfig.class);
}
@Configuration
@ComponentScan(basePackageClasses=ScannedEnableWebMvcNoConfigurationAnnotationConfig.class)
static class EnableWebMvcWithClasspathScanningConfig {}
private void assertLoadsWebMvc(Class<?>... configs) {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletConfig(new MockServletConfig());
context.setServletContext(new MockServletContext());
context.register(configs);
context.refresh();
context.start();
// verify RequestMappingHandlerMapping is found
context.getBean(RequestMappingHandlerMapping.class);
this.context = context;
}
}
package package sample.scanning;
... imports omitted...
@EnableWebMvc
public class ScannedEnableWebMvcNoConfigurationAnnotationConfig {
}
Issue Links:
- Consider @Import classes as lite @Configuration [SPR-10533] #15163 Consider
@Import
classes as lite@Configuration
("duplicates")
Referenced from: commits d18b3f0