From 7da129539fbb3cfb687ad0099ba1c83127c3ab05 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 29 May 2016 13:19:09 +0200 Subject: [PATCH] @Bean's "autowire" attribute does not affect annotation-driven autowiring Issue: SPR-14282 (cherry picked from commit 98eaf05) --- .../context/annotation/Bean.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) 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 5c0fcd6805..8cbaa0da3b 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,8 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; * public MyBean myBean() { * // instantiate and configure MyBean obj * return obj; - * } + * } + * * *

Bean Names

* @@ -55,7 +56,8 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; * public MyBean myBean() { * // instantiate and configure MyBean obj * return obj; - * } + * } + * * *

Scope, DependsOn, Primary, and Lazy

* @@ -70,7 +72,8 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; * public MyBean myBean() { * // instantiate and configure MyBean obj * return obj; - * } + * } + * * *

{@code @Bean} Methods in {@code @Configuration} Classes

* @@ -87,14 +90,17 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; *
  * @Configuration
  * public class AppConfig {
+ *
  *     @Bean
  *     public FooService fooService() {
  *         return new FooService(fooRepository());
  *     }
+ *
  *     @Bean
  *     public FooRepository fooRepository() {
  *         return new JdbcFooRepository(dataSource());
  *     }
+ *
  *     // ...
  * }
* @@ -152,7 +158,8 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; * @Bean * public static PropertyPlaceholderConfigurer ppc() { * // instantiate, configure and return ppc ... - * } + * } + * * * 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. @@ -191,6 +198,13 @@ public @interface Bean { /** * Are dependencies to be injected via convention-based autowiring by name or type? + *

Note that this autowire mode is just about externally driven autowiring based + * on bean property setter methods by convention, analogous to XML bean definitions. + *

The default mode does allow for annotation-driven autowiring. "no" refers to + * externally driven autowiring only, not affecting any autowiring demands that the + * bean class itself expresses through annotations. + * @see Autowire#BY_NAME + * @see Autowire#BY_TYPE */ Autowire autowire() default Autowire.NO;