Refine AliasFor usage
This commit makes sure to use `getAliasedStringArray` rather than `getStringArray` as the latter does not work with ASM. While this will probably be fixed in the core framework, this commit also adds dedicated tests with ASM to ensure that the code works as expected. Closes gh-6337
This commit is contained in:
@@ -155,7 +155,8 @@ public class EntityScanPackages {
|
||||
private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
|
||||
AnnotationAttributes attributes = AnnotationAttributes.fromMap(
|
||||
metadata.getAnnotationAttributes(EntityScan.class.getName()));
|
||||
String[] basePackages = attributes.getStringArray("basePackages");
|
||||
String[] basePackages = attributes.getAliasedStringArray("basePackages",
|
||||
EntityScan.class, metadata.getClassName());
|
||||
Class<?>[] basePackageClasses = attributes
|
||||
.getClassArray("basePackageClasses");
|
||||
Set<String> packagesToScan = new LinkedHashSet<String>();
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.AnnotationConfigurationException;
|
||||
@@ -112,6 +113,17 @@ public class EntityScanPackagesTests {
|
||||
assertThat(packages.getPackageNames()).containsExactly("a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void entityScanAnnotationWhenHasValueAttributeShouldSetupPackagesAsm()
|
||||
throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.registerBeanDefinition("entityScanValueConfig",
|
||||
new RootBeanDefinition(EntityScanValueConfig.class.getName()));
|
||||
this.context.refresh();
|
||||
EntityScanPackages packages = EntityScanPackages.get(this.context);
|
||||
assertThat(packages.getPackageNames()).containsExactly("a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void entityScanAnnotationWhenHasBasePackagesAttributeShouldSetupPackages()
|
||||
throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user