Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract packages from SpringBootApplication or ComponentScan if EnableFeignClients does not set basePackages or basePackageClasses #1113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,65 @@ protected Set<String> getBasePackages(AnnotationMetadata importingClassMetadata)
basePackages.add(ClassUtils.getPackageName(clazz));
}

if (basePackages.isEmpty()) {
// org.springframework.boot.autoconfigure.SpringBootApplication
String bootAppClassName = "org.springframework.boot.autoconfigure.SpringBootApplication";
if (importingClassMetadata.hasAnnotation(bootAppClassName)){
Map<String, Object> bootAttributes = importingClassMetadata
.getAnnotationAttributes(bootAppClassName);
for (String pkg : (String[]) bootAttributes.get("scanBasePackages")) {
if (StringUtils.hasText(pkg)) {
basePackages.add(pkg);
}
}
for (Class<?> clazz : (Class[]) bootAttributes.get("scanBasePackageClasses")) {
basePackages.add(ClassUtils.getPackageName(clazz));
}
}

String componentScanClassName = "org.springframework.context.annotation.ComponentScan";
if (importingClassMetadata.hasAnnotation(componentScanClassName)) {
Map<String, Object> scanAttributes = importingClassMetadata
.getAnnotationAttributes(componentScanClassName);
for (String pkg : (String[]) scanAttributes.get("value")) {
if (StringUtils.hasText(pkg)) {
basePackages.add(pkg);
}
}
for (String pkg : (String[]) scanAttributes.get("basePackages")) {
if (StringUtils.hasText(pkg)) {
basePackages.add(pkg);
}
}
for (Class<?> clazz : (Class[]) scanAttributes.get("basePackageClasses")) {
basePackages.add(ClassUtils.getPackageName(clazz));
}
}

String componentScansClassName = "org.springframework.context.annotation.ComponentScans";
if (importingClassMetadata.hasAnnotation(componentScansClassName)) {
Map<String, Object> componentScansAttrs =
importingClassMetadata.getAnnotationAttributes(componentScansClassName);
AnnotationAttributes[] componentScanAttributes =
(AnnotationAttributes[]) componentScansAttrs.get("value");
for (AnnotationAttributes scanAttributes : componentScanAttributes) {
for (String pkg : (String[]) scanAttributes.get("value")) {
if (StringUtils.hasText(pkg)) {
basePackages.add(pkg);
}
}
for (String pkg : (String[]) scanAttributes.get("basePackages")) {
if (StringUtils.hasText(pkg)) {
basePackages.add(pkg);
}
}
for (Class<?> clazz : (Class[]) scanAttributes.get("basePackageClasses")) {
basePackages.add(ClassUtils.getPackageName(clazz));
}
}
}
}

if (basePackages.isEmpty()) {
basePackages.add(ClassUtils.getPackageName(importingClassMetadata.getClassName()));
}
Expand Down