diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackage.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackage.java
index 0fbe9b9a668..8b4ff1ac717 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackage.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackage.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,8 +26,9 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
/**
- * Indicates that the package containing the annotated class should be registered with
- * {@link AutoConfigurationPackages}.
+ * Registers packages with {@link AutoConfigurationPackages}. When no {@link #basePackages
+ * base packages} or {@link #basePackageClasses base package classes} are specified, the
+ * package of the annotated class is registered.
*
* @author Phillip Webb
* @since 1.3.0
@@ -40,4 +41,25 @@ import org.springframework.context.annotation.Import;
@Import(AutoConfigurationPackages.Registrar.class)
public @interface AutoConfigurationPackage {
+ /**
+ * Base packages that should be registered with {@link AutoConfigurationPackages}.
+ *
+ * Use {@link #basePackageClasses} for a type-safe alternative to String-based package
+ * names.
+ * @return the back package names
+ * @since 2.3.0
+ */
+ String[] basePackages() default {};
+
+ /**
+ * Type-safe alternative to {@link #basePackages} for specifying the packages to be
+ * registered with {@link AutoConfigurationPackages}.
+ *
+ * Consider creating a special no-op marker class or interface in each package that
+ * serves no purpose other than being referenced by this attribute.
+ * @return the base package classes
+ * @since 2.3.0
+ */
+ Class>[] basePackageClasses() default {};
+
}
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackages.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackages.java
index 520af8e4617..d37dc97f569 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackages.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackages.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.boot.context.annotation.DeterminableImports;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
+import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -120,12 +121,12 @@ public abstract class AutoConfigurationPackages {
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
- register(registry, new PackageImport(metadata).getPackageName());
+ register(registry, new PackageImports(metadata).getPackageNames().toArray(new String[0]));
}
@Override
public Set