Merge branch 'gh-3943'

pull/3967/head
Andy Wilkinson 9 years ago
commit be07a8a4c2

@ -57,12 +57,11 @@ 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(packagesToScan);
constructorArguments.setValue(mergedPackages);
}
private void addPostProcessor(BeanDefinitionRegistry registry,

@ -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