mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Polishing
This commit is contained in:
+1
@@ -128,6 +128,7 @@ final class ConfigurationClass {
|
||||
* @param metadata the metadata for the underlying class to represent
|
||||
* @param beanName name of the {@code @Configuration} class bean
|
||||
* @param scanned whether the underlying class has been registered through a scan
|
||||
* @since 6.2
|
||||
*/
|
||||
ConfigurationClass(AnnotationMetadata metadata, String beanName, boolean scanned) {
|
||||
Assert.notNull(beanName, "Bean name must not be null");
|
||||
|
||||
+13
-10
@@ -18,10 +18,7 @@ package org.springframework.context.annotation;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -194,13 +191,19 @@ class ConfigurationClassBeanDefinitionReader {
|
||||
AnnotationAttributes bean = AnnotationConfigUtils.attributesFor(metadata, Bean.class);
|
||||
Assert.state(bean != null, "No @Bean annotation attributes");
|
||||
|
||||
// Consider name and any aliases
|
||||
List<String> names = new ArrayList<>(Arrays.asList(bean.getStringArray("name")));
|
||||
String beanName = (!names.isEmpty() ? names.remove(0) : methodName);
|
||||
|
||||
// Register aliases even when overridden
|
||||
for (String alias : names) {
|
||||
this.registry.registerAlias(beanName, alias);
|
||||
// Consider name and any aliases.
|
||||
String[] explicitNames = bean.getStringArray("name");
|
||||
String beanName;
|
||||
if (explicitNames.length > 0) {
|
||||
beanName = explicitNames[0];
|
||||
// Register aliases even when overridden below.
|
||||
for (int i = 1; i < explicitNames.length; i++) {
|
||||
this.registry.registerAlias(beanName, explicitNames[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Default bean name derived from method name.
|
||||
beanName = methodName;
|
||||
}
|
||||
|
||||
// Has this effectively been overridden before (for example, via XML)?
|
||||
|
||||
Reference in New Issue
Block a user