diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java b/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java index 5d3b67779dc..9cb02b7dd74 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java @@ -84,7 +84,22 @@ import org.springframework.stereotype.Component; * {@code @Configuration} classes are candidates for component scanning (typically using * Spring XML's {@code } element) and therefore may also take * advantage of {@link Autowired @Autowired}/{@link javax.inject.Inject @Inject} - * at the field and method level (but not at the constructor level). + * like any regular {@code @Component}. In particular, if a single constructor is present + * autowiring semantics will be applied transparently: + * + *
+ * @Configuration
+ * public class AppConfig {
+ *     private final SomeBean someBean;
+ *
+ *     public AppConfig(SomeBean someBean) {
+ *         this.someBean = someBean;
+ *     }
+ *
+ *     // @Bean definition using "SomeBean"
+ *
+ * }
+ * *

{@code @Configuration} classes may not only be bootstrapped using * component scanning, but may also themselves configure component scanning using * the {@link ComponentScan @ComponentScan} annotation: @@ -104,13 +119,13 @@ import org.springframework.stereotype.Component; * * Externalized values may be looked up by injecting the Spring * {@link org.springframework.core.env.Environment} into a {@code @Configuration} - * class using the {@code @Autowired} or the {@code @Inject} annotation: + * class the usual (e.g. using the {@code @Autowired} annotation): * *

  * @Configuration
  * public class AppConfig {
  *
- *     @Inject Environment env;
+ *     @Autowired Environment env;
  *
  *     @Bean
  *     public MyBean myBean() {
@@ -175,7 +190,7 @@ import org.springframework.stereotype.Component;
  * 

{@code @Configuration} classes may be composed using the {@link Import @Import} annotation, * not unlike the way that {@code } works in Spring XML. Because * {@code @Configuration} objects are managed as Spring beans within the container, - * imported configurations may be injected using {@code @Autowired} or {@code @Inject}: + * imported configurations may be injected the usual way (e.g. via constructor injection): * *

  * @Configuration
@@ -191,7 +206,11 @@ import org.springframework.stereotype.Component;
  * @Import(DatabaseConfig.class)
  * public class AppConfig {
  *
- *     @Inject DatabaseConfig dataConfig;
+ *     private final DatabaseConfig dataConfig;
+ *
+ *     public AppConfig(DatabaseConfig dataConfig) {
+ *         this.dataConfig = dataConfig;
+ *     }
  *
  *     @Bean
  *     public MyBean myBean() {
@@ -240,8 +259,8 @@ import org.springframework.stereotype.Component;
  * As mentioned above, {@code @Configuration} classes may be declared as regular Spring
  * {@code } definitions within Spring XML files. It is also possible to
  * import Spring XML configuration files into {@code @Configuration} classes using
- * the {@link ImportResource @ImportResource} annotation. Bean definitions imported from XML can be
- * injected using {@code @Autowired} or {@code @Inject}:
+ * the {@link ImportResource @ImportResource} annotation. Bean definitions imported from
+ * XML can be injected the usual way (e.g. using the {@code Inject} annotation):
  *
  * 
  * @Configuration
@@ -340,9 +359,7 @@ import org.springframework.stereotype.Component;
  * 
    *
  • @Configuration classes must be non-final *
  • @Configuration classes must be non-local (may not be declared within a method) - *
  • @Configuration classes must have a default/no-arg constructor and may not use - * {@link Autowired @Autowired} constructor parameters. Any nested configuration classes - * must be {@code static}. + *
  • Any nested configuration classes must be {@code static}. *
* * @author Rod Johnson