Skip to content

Commit 7bec780

Browse files
vivimicewilkinsona
authored andcommitted
Use modifiable set for @ServletComponentScan with no packages
Previously, when a project contained multiple `@ServletComponentScan` annotated classes in classpath, and at least one annotation don't explicitly specify `basePackages` and `basePackageClass` attribute, the application could fail to start with an UnsupportedOperationException. The failure occurred due to the creating of an unmodifiable set when no base packages are configured and a subsequent attempt to add base packages to that sit. This commit fixes the issue by removing the use of an unmodifiable set when `@ServletComponentScan` with no base packages in processed before any other `@ServletComponentScan` annotations. See gh-12715
1 parent 2fd177f commit 7bec780

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrar.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.web.servlet;
1818

1919
import java.util.Arrays;
20-
import java.util.Collections;
2120
import java.util.LinkedHashSet;
2221
import java.util.Set;
2322

@@ -84,8 +83,7 @@ private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
8483
packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
8584
}
8685
if (packagesToScan.isEmpty()) {
87-
return Collections
88-
.singleton(ClassUtils.getPackageName(metadata.getClassName()));
86+
packagesToScan.add(ClassUtils.getPackageName(metadata.getClassName()));
8987
}
9088
return packagesToScan;
9189
}

0 commit comments

Comments
 (0)