diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Bean.java b/spring-context/src/main/java/org/springframework/context/annotation/Bean.java index 8b4f45ac1d..b15b7c8ef8 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Bean.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Bean.java @@ -46,14 +46,14 @@ import org.springframework.core.annotation.AliasFor; *
While a {@link #name} attribute is available, the default strategy for - * determining the name of a bean is to use the name of the {@code @Bean} method. This - * is convenient and intuitive, but if explicit naming is desired, the {@code name} - * attribute (or its alias {@code value}) may be used. Also note that {@code name} - * accepts an array of Strings. This is in order to allow for specifying multiple names - * (i.e., aliases) for a single bean. + * determining the name of a bean is to use the name of the {@code @Bean} method. + * This is convenient and intuitive, but if explicit naming is desired, the + * {@code name} attribute (or its alias {@code value}) may be used. Also note + * that {@code name} accepts an array of Strings, allowing for multiple names + * (i.e. a primary bean name plus one or more aliases) for a single bean. * *
- * @Bean({"b1","b2"}) // bean available as 'b1' and 'b2', but not 'myBean'
+ * @Bean({"b1", "b2"}) // bean available as 'b1' and 'b2', but not 'myBean'
* public MyBean myBean() {
* // instantiate and configure MyBean obj
* return obj;
@@ -79,9 +79,9 @@ import org.springframework.core.annotation.AliasFor;
* {@code @Bean} Methods in {@code @Configuration} Classes
*
* Typically, {@code @Bean} methods are declared within {@code @Configuration}
- * classes. In this case, bean methods may reference other {@code @Bean} methods
- * in the same class by calling them directly. This ensures that references between
- * beans are strongly typed and navigable. Such so-called 'inter-bean references' are
+ * classes. In this case, bean methods may reference other {@code @Bean} methods in the
+ * same class by calling them directly. This ensures that references between beans
+ * are strongly typed and navigable. Such so-called 'inter-bean references' are
* guaranteed to respect scoping and AOP semantics, just like {@code getBean()} lookups
* would. These are the semantics known from the original 'Spring JavaConfig' project
* which require CGLIB subclassing of each such configuration class at runtime. As a
@@ -194,15 +194,15 @@ public @interface Bean {
* Alias for {@link #name}.
*
Intended to be used when no other attributes are needed, for example:
* {@code @Bean("customBeanName")}.
- * @since 5.0
+ * @since 4.3.3
* @see #name
*/
@AliasFor("name")
String[] value() default {};
/**
- * The name of this bean, or if plural, aliases for this bean.
- *
If left unspecified the name of the bean is the name of the annotated method.
+ * The name of this bean, or if several names, a primary bean name plus aliases.
+ *
If left unspecified, the name of the bean is the name of the annotated method.
* If specified, the method name is ignored.
*
The bean name and aliases may also be configured via the {@link #value}
* attribute if no other attributes are declared.
diff --git a/spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java b/spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java
index b1360a5bf4..88d27eaca7 100644
--- a/spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java
+++ b/spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java
@@ -21,7 +21,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
-
import javax.inject.Provider;
import org.junit.Rule;
@@ -279,6 +278,7 @@ public class ConfigurationClassProcessingTests {
}
}
+
@Configuration
static class ConfigWithBeanWithCustomNameConfiguredViaValueAttribute {
@@ -290,6 +290,7 @@ public class ConfigurationClassProcessingTests {
}
}
+
@Configuration
static class ConfigWithBeanWithAliases {
@@ -301,6 +302,7 @@ public class ConfigurationClassProcessingTests {
}
}
+
@Configuration
static class ConfigWithBeanWithAliasesConfiguredViaValueAttribute {
@@ -452,7 +454,7 @@ public class ConfigurationClassProcessingTests {
};
}
- //@Bean
+ // @Bean
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
return new BeanFactoryPostProcessor() {
@Override