@@ -410,6 +410,65 @@ protected Set<String> getBasePackages(AnnotationMetadata importingClassMetadata)
410
410
basePackages .add (ClassUtils .getPackageName (clazz ));
411
411
}
412
412
413
+ if (basePackages .isEmpty ()) {
414
+ // org.springframework.boot.autoconfigure.SpringBootApplication
415
+ String bootAppClassName = "org.springframework.boot.autoconfigure.SpringBootApplication" ;
416
+ if (importingClassMetadata .hasAnnotation (bootAppClassName )){
417
+ Map <String , Object > bootAttributes = importingClassMetadata
418
+ .getAnnotationAttributes (bootAppClassName );
419
+ for (String pkg : (String []) bootAttributes .get ("scanBasePackages" )) {
420
+ if (StringUtils .hasText (pkg )) {
421
+ basePackages .add (pkg );
422
+ }
423
+ }
424
+ for (Class <?> clazz : (Class []) bootAttributes .get ("scanBasePackageClasses" )) {
425
+ basePackages .add (ClassUtils .getPackageName (clazz ));
426
+ }
427
+ }
428
+
429
+ String componentScanClassName = "org.springframework.context.annotation.ComponentScan" ;
430
+ if (importingClassMetadata .hasAnnotation (componentScanClassName )) {
431
+ Map <String , Object > scanAttributes = importingClassMetadata
432
+ .getAnnotationAttributes (componentScanClassName );
433
+ for (String pkg : (String []) scanAttributes .get ("value" )) {
434
+ if (StringUtils .hasText (pkg )) {
435
+ basePackages .add (pkg );
436
+ }
437
+ }
438
+ for (String pkg : (String []) scanAttributes .get ("basePackages" )) {
439
+ if (StringUtils .hasText (pkg )) {
440
+ basePackages .add (pkg );
441
+ }
442
+ }
443
+ for (Class <?> clazz : (Class []) scanAttributes .get ("basePackageClasses" )) {
444
+ basePackages .add (ClassUtils .getPackageName (clazz ));
445
+ }
446
+ }
447
+
448
+ String componentScansClassName = "org.springframework.context.annotation.ComponentScans" ;
449
+ if (importingClassMetadata .hasAnnotation (componentScansClassName )) {
450
+ Map <String , Object > componentScansAttrs =
451
+ importingClassMetadata .getAnnotationAttributes (componentScansClassName );
452
+ AnnotationAttributes [] componentScanAttributes =
453
+ (AnnotationAttributes []) componentScansAttrs .get ("value" );
454
+ for (AnnotationAttributes scanAttributes : componentScanAttributes ) {
455
+ for (String pkg : (String []) scanAttributes .get ("value" )) {
456
+ if (StringUtils .hasText (pkg )) {
457
+ basePackages .add (pkg );
458
+ }
459
+ }
460
+ for (String pkg : (String []) scanAttributes .get ("basePackages" )) {
461
+ if (StringUtils .hasText (pkg )) {
462
+ basePackages .add (pkg );
463
+ }
464
+ }
465
+ for (Class <?> clazz : (Class []) scanAttributes .get ("basePackageClasses" )) {
466
+ basePackages .add (ClassUtils .getPackageName (clazz ));
467
+ }
468
+ }
469
+ }
470
+ }
471
+
413
472
if (basePackages .isEmpty ()) {
414
473
basePackages .add (ClassUtils .getPackageName (importingClassMetadata .getClassName ()));
415
474
}
0 commit comments