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) { Set<String> packagesToScan) {
BeanDefinition definition = registry.getBeanDefinition(BEAN_NAME); BeanDefinition definition = registry.getBeanDefinition(BEAN_NAME);
ValueHolder constructorArguments = definition.getConstructorArgumentValues() ValueHolder constructorArguments = definition.getConstructorArgumentValues()
.getGenericArgumentValue(String[].class); .getGenericArgumentValue(Set.class);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Set<String> mergedPackages = new LinkedHashSet<String>( Set<String> mergedPackages = (Set<String>) constructorArguments.getValue();
(Set<String>) constructorArguments.getValue());
mergedPackages.addAll(packagesToScan); mergedPackages.addAll(packagesToScan);
constructorArguments.setValue(packagesToScan); constructorArguments.setValue(mergedPackages);
} }
private void addPostProcessor(BeanDefinitionRegistry registry, private void addPostProcessor(BeanDefinitionRegistry registry,

@ -84,6 +84,18 @@ public class ServletComponentScanRegistrarTests {
.getPackage().getName())); .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 @Configuration
@ServletComponentScan({ "com.example.foo", "com.example.bar" }) @ServletComponentScan({ "com.example.foo", "com.example.bar" })
static class ValuePackages { static class ValuePackages {
@ -96,6 +108,12 @@ public class ServletComponentScanRegistrarTests {
} }
@Configuration
@ServletComponentScan(basePackages = "com.example.baz")
static class AdditionalPackages {
}
@Configuration @Configuration
@ServletComponentScan(basePackageClasses = ServletComponentScanRegistrarTests.class) @ServletComponentScan(basePackageClasses = ServletComponentScanRegistrarTests.class)
static class BasePackageClasses { static class BasePackageClasses {

Loading…
Cancel
Save