Add test for merging packages from multiple @ServletComponentScans

pull/3967/head
Andy Wilkinson 9 years ago
parent 20da79e9bd
commit bfc0745616

@ -57,10 +57,9 @@ class ServletComponentScanRegistrar implements ImportBeanDefinitionRegistrar {
Set<String> packagesToScan) {
BeanDefinition definition = registry.getBeanDefinition(BEAN_NAME);
ValueHolder constructorArguments = definition.getConstructorArgumentValues()
.getGenericArgumentValue(String[].class);
.getGenericArgumentValue(Set.class);
@SuppressWarnings("unchecked")
Set<String> mergedPackages = new LinkedHashSet<String>(
(Set<String>) constructorArguments.getValue());
Set<String> mergedPackages = (Set<String>) constructorArguments.getValue();
mergedPackages.addAll(packagesToScan);
constructorArguments.setValue(mergedPackages);
}

@ -84,6 +84,18 @@ public class ServletComponentScanRegistrarTests {
.getPackage().getName()));
}
@Test
public void packagesFromMultipleAnnotationsAreMerged() {
this.context = new AnnotationConfigApplicationContext(BasePackages.class,
AdditionalPackages.class);
ServletComponentRegisteringPostProcessor postProcessor = this.context
.getBean(ServletComponentRegisteringPostProcessor.class);
assertThat(
postProcessor.getPackagesToScan(),
containsInAnyOrder("com.example.foo", "com.example.bar",
"com.example.baz"));
}
@Configuration
@ServletComponentScan({ "com.example.foo", "com.example.bar" })
static class ValuePackages {
@ -96,6 +108,12 @@ public class ServletComponentScanRegistrarTests {
}
@Configuration
@ServletComponentScan(basePackages = "com.example.baz")
static class AdditionalPackages {
}
@Configuration
@ServletComponentScan(basePackageClasses = ServletComponentScanRegistrarTests.class)
static class BasePackageClasses {

Loading…
Cancel
Save