diff --git a/framework-docs/modules/ROOT/pages/core/beans/factory-extension.adoc b/framework-docs/modules/ROOT/pages/core/beans/factory-extension.adoc index 2becb1d7eed..586172de1d3 100644 --- a/framework-docs/modules/ROOT/pages/core/beans/factory-extension.adoc +++ b/framework-docs/modules/ROOT/pages/core/beans/factory-extension.adoc @@ -135,7 +135,7 @@ Java:: } public Object postProcessAfterInitialization(Object bean, String beanName) { - System.out.println("Bean '" + beanName + "' created : " + bean.toString()); + System.out.println("Bean '" + beanName + "' created : " + bean); return bean; } } @@ -192,7 +192,7 @@ The following `beans` element uses the `InstantiationTracingBeanPostProcessor`: ---- Notice how the `InstantiationTracingBeanPostProcessor` is merely defined. It does not -even have a name, and, because it is a bean, it can be dependency-injected as you would any +even have a name, and, because it is a bean, it can be dependency-injected as with any other bean. (The preceding configuration also defines a bean that is backed by a Groovy script.) 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 6807518cf1d..37d56f742e3 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 @@ -35,12 +35,11 @@ import org.springframework.core.annotation.AliasFor; * example: * *
- *     @Bean
- *     public MyBean myBean() {
- *         // instantiate and configure MyBean obj
- *         return obj;
- *     }
- * 
+ * @Bean + * public MyBean myBean() { + * // instantiate and configure MyBean obj + * return obj; + * } * *

Bean Names

* @@ -52,12 +51,11 @@ import org.springframework.core.annotation.AliasFor; * (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'
- *     public MyBean myBean() {
- *         // instantiate and configure MyBean obj
- *         return obj;
- *     }
- * 
+ * @Bean({"b1", "b2"}) // bean available as 'b1' and 'b2', but not 'myBean' + * public MyBean myBean() { + * // instantiate and configure MyBean obj + * return obj; + * } * *

Profile, Scope, Lazy, DependsOn, Primary, Order

* @@ -67,16 +65,15 @@ import org.springframework.core.annotation.AliasFor; * {@link Primary @Primary} annotations to declare those semantics. For example: * *
- *     @Bean
- *     @Profile("production")
- *     @Scope("prototype")
- *     public MyBean myBean() {
- *         // instantiate and configure MyBean obj
- *         return obj;
- *     }
- * 
+ * @Bean + * @Profile("production") + * @Scope("prototype") + * public MyBean myBean() { + * // instantiate and configure MyBean obj + * return obj; + * } * - * The semantics of the above-mentioned annotations match their use at the component + * The semantics of the aforementioned annotations match their use at the component * class level: {@code @Profile} allows for selective inclusion of certain beans. * {@code @Scope} changes the bean's scope from singleton to the specified scope. * {@code @Lazy} only has an actual effect in case of the default singleton scope. @@ -119,17 +116,17 @@ import org.springframework.core.annotation.AliasFor; * @Configuration * public class AppConfig { * - * @Bean - * public FooService fooService() { - * return new FooService(fooRepository()); - * } + * @Bean + * public FooService fooService() { + * return new FooService(fooRepository()); + * } * - * @Bean - * public FooRepository fooRepository() { - * return new JdbcFooRepository(dataSource()); - * } + * @Bean + * public FooRepository fooRepository() { + * return new JdbcFooRepository(dataSource()); + * } * - * // ... + * // ... * } * *

{@code @Bean} Lite Mode

@@ -158,20 +155,21 @@ import org.springframework.core.annotation.AliasFor; *
  * @Component
  * public class Calculator {
- *     public int sum(int a, int b) {
- *         return a+b;
- *     }
+ *    public int sum(int a, int b) {
+ *        return a+b;
+ *    }
  *
- *     @Bean
- *     public MyBean myBean() {
- *         return new MyBean();
- *     }
+ *    @Bean
+ *    public MyBean myBean() {
+ *        return new MyBean();
+ *    }
  * }
* *

Bootstrapping

* - *

See the @{@link Configuration} javadoc for further details including how to bootstrap - * the container using {@link AnnotationConfigApplicationContext} and friends. + *

See the {@link Configuration @Configuration} javadoc for further details + * including how to bootstrap the container using + * {@link AnnotationConfigApplicationContext} and friends. * *

{@code BeanFactoryPostProcessor}-returning {@code @Bean} methods

* @@ -183,14 +181,13 @@ import org.springframework.core.annotation.AliasFor; * lifecycle issues, mark {@code BFPP}-returning {@code @Bean} methods as {@code static}. For example: * *
- *     @Bean
- *     public static PropertySourcesPlaceholderConfigurer pspc() {
- *         // instantiate, configure and return pspc ...
- *     }
- * 
+ * @Bean + * public static PropertySourcesPlaceholderConfigurer pspc() { + * // instantiate, configure and return pspc ... + * } * * By marking this method as {@code static}, it can be invoked without causing instantiation of its - * declaring {@code @Configuration} class, thus avoiding the above-mentioned lifecycle conflicts. + * declaring {@code @Configuration} class, thus avoiding the aforementioned lifecycle conflicts. * Note however that {@code static} {@code @Bean} methods will not be enhanced for scoping and AOP * semantics as mentioned above. This works out in {@code BFPP} cases, as they are not typically * referenced by other {@code @Bean} methods. As a reminder, an INFO-level log message will be