|
|
|
@ -32,6 +32,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
|
|
|
|
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
|
|
|
|
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
|
|
|
|
import org.springframework.core.annotation.AnnotationAttributes;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.core.type.AnnotationMetadata;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
@ -124,6 +125,12 @@ public class EntityScanPackages {
|
|
|
|
|
*/
|
|
|
|
|
static class Registrar implements ImportBeanDefinitionRegistrar {
|
|
|
|
|
|
|
|
|
|
private final Environment environment;
|
|
|
|
|
|
|
|
|
|
Registrar(Environment environment) {
|
|
|
|
|
this.environment = environment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
|
|
|
|
|
register(registry, getPackagesToScan(metadata));
|
|
|
|
@ -132,11 +139,12 @@ public class EntityScanPackages {
|
|
|
|
|
private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
|
|
|
|
|
AnnotationAttributes attributes = AnnotationAttributes
|
|
|
|
|
.fromMap(metadata.getAnnotationAttributes(EntityScan.class.getName()));
|
|
|
|
|
String[] basePackages = attributes.getStringArray("basePackages");
|
|
|
|
|
Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
|
|
|
|
|
Set<String> packagesToScan = new LinkedHashSet<>(Arrays.asList(basePackages));
|
|
|
|
|
for (Class<?> basePackageClass : basePackageClasses) {
|
|
|
|
|
packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
|
|
|
|
|
Set<String> packagesToScan = new LinkedHashSet<>();
|
|
|
|
|
for (String basePackage : attributes.getStringArray("basePackages")) {
|
|
|
|
|
addResolvedPackage(basePackage, packagesToScan);
|
|
|
|
|
}
|
|
|
|
|
for (Class<?> basePackageClass : attributes.getClassArray("basePackageClasses")) {
|
|
|
|
|
addResolvedPackage(ClassUtils.getPackageName(basePackageClass), packagesToScan);
|
|
|
|
|
}
|
|
|
|
|
if (packagesToScan.isEmpty()) {
|
|
|
|
|
String packageName = ClassUtils.getPackageName(metadata.getClassName());
|
|
|
|
@ -146,6 +154,10 @@ public class EntityScanPackages {
|
|
|
|
|
return packagesToScan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addResolvedPackage(String packageName, Set<String> packagesToScan) {
|
|
|
|
|
packagesToScan.add(this.environment.resolvePlaceholders(packageName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static class EntityScanPackagesBeanDefinition extends GenericBeanDefinition {
|
|
|
|
|