Browse Source

Update documentation

Issue: SPR-12278
pull/925/merge
Stephane Nicoll 9 years ago
parent
commit
edd8e2d56d
  1. 47
      src/asciidoc/core-beans.adoc
  2. 6
      src/asciidoc/whats-new.adoc

47
src/asciidoc/core-beans.adoc

@ -4168,18 +4168,24 @@ references and values even when you use the class outside of a container.
[[beans-autowired-annotation]] [[beans-autowired-annotation]]
=== @Autowired === @Autowired
As expected, you can apply the `@Autowired` annotation to "traditional" setter methods: [NOTE]
====
JSR 330's `@Inject` annotation can be used in place of Spring's `@Autowired` annotation
in the examples below. See <<beans-standard-annotations,here>> for more details.
====
You can apply the `@Autowired` annotation to constructors:
[source,java,indent=0] [source,java,indent=0]
[subs="verbatim,quotes"] [subs="verbatim,quotes"]
---- ----
public class SimpleMovieLister { public class MovieRecommender {
private MovieFinder movieFinder; private final CustomerPreferenceDao customerPreferenceDao;
@Autowired @Autowired
public void setMovieFinder(MovieFinder movieFinder) { public MovieRecommender(CustomerPreferenceDao customerPreferenceDao) {
this.movieFinder = movieFinder; this.customerPreferenceDao = customerPreferenceDao;
} }
// ... // ...
@ -4189,10 +4195,31 @@ As expected, you can apply the `@Autowired` annotation to "traditional" setter m
[NOTE] [NOTE]
==== ====
JSR 330's `@Inject` annotation can be used in place of Spring's `@Autowired` annotation As of Spring Framework 4.3, the `@Autowired` constructor is no longer necessary if the
in the examples below. See <<beans-standard-annotations,here>> for more details. target bean only defines one constructor. If several constructors are available, at
least one must be annotated to teach the container which one it has to use.
==== ====
As expected, you can also apply the `@Autowired` annotation to "traditional" setter
methods:
[source,java,indent=0]
[subs="verbatim,quotes"]
----
public class SimpleMovieLister {
private MovieFinder movieFinder;
@Autowired
public void setMovieFinder(MovieFinder movieFinder) {
this.movieFinder = movieFinder;
}
// ...
}
----
You can also apply the annotation to methods with arbitrary names and/or multiple You can also apply the annotation to methods with arbitrary names and/or multiple
arguments: arguments:
@ -4217,18 +4244,18 @@ arguments:
} }
---- ----
You can apply `@Autowired` to constructors and fields: You can apply `@Autowired` to fields as well and even mix it with constructors:
[source,java,indent=0] [source,java,indent=0]
[subs="verbatim,quotes"] [subs="verbatim,quotes"]
---- ----
public class MovieRecommender { public class MovieRecommender {
private final CustomerPreferenceDao customerPreferenceDao;
@Autowired @Autowired
private MovieCatalog movieCatalog; private MovieCatalog movieCatalog;
private CustomerPreferenceDao customerPreferenceDao;
@Autowired @Autowired
public MovieRecommender(CustomerPreferenceDao customerPreferenceDao) { public MovieRecommender(CustomerPreferenceDao customerPreferenceDao) {
this.customerPreferenceDao = customerPreferenceDao; this.customerPreferenceDao = customerPreferenceDao;

6
src/asciidoc/whats-new.adoc

@ -627,6 +627,12 @@ public @interface MyTestConfig {
[[new-in-4.3]] [[new-in-4.3]]
== New Features and Enhancements in Spring Framework 4.3 == New Features and Enhancements in Spring Framework 4.3
=== Core Container Improvements
* It is no longer necessary to specify the `@Autowired` annotation if the target
bean only define one constructor.
=== Testing Improvements === Testing Improvements
* The JUnit support in the _Spring TestContext Framework_ now requires JUnit 4.12 or higher. * The JUnit support in the _Spring TestContext Framework_ now requires JUnit 4.12 or higher.

Loading…
Cancel
Save