diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Scope.java b/spring-context/src/main/java/org/springframework/context/annotation/Scope.java index b0daf8c0cec..cf64e8acd59 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Scope.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Scope.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -35,6 +35,12 @@ import org.springframework.core.annotation.AliasFor; * {@link Bean @Bean}, {@code @Scope} indicates the name of a scope to use * for the instance returned from the method. * + *
NOTE: {@code @Scope} annotations are only introspected on the + * concrete bean class (for annotated components) or the factory method + * (for {@code @Bean} methods). In contrast to XML bean definitions, + * there is no notion of bean definition inheritance, and inheritance + * hierarchies at the class level are irrelevant for metadata purposes. + * *
In this context, scope means the lifecycle of an instance,
* such as {@code singleton}, {@code prototype}, and so forth. Scopes
* provided out of the box in Spring may be referred to using the
diff --git a/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java b/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java
index 51b6c0b5d6f..23f3d37c598 100644
--- a/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java
+++ b/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2018 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.
@@ -1391,9 +1391,19 @@ public class XmlBeanFactoryTests {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.loadBeanDefinitions(OVERRIDES_CONTEXT);
- TestBean jenny = (TestBean) xbf.getBean("jennyChild");
- assertEquals(1, jenny.getFriends().size());
- assertTrue(jenny.getFriends().iterator().next() instanceof TestBean);
+
+ TestBean jenny1 = (TestBean) xbf.getBean("jennyChild");
+ assertEquals(1, jenny1.getFriends().size());
+ Object friend1 = jenny1.getFriends().iterator().next();
+ assertTrue(friend1 instanceof TestBean);
+
+ TestBean jenny2 = (TestBean) xbf.getBean("jennyChild");
+ assertEquals(1, jenny2.getFriends().size());
+ Object friend2 = jenny2.getFriends().iterator().next();
+ assertTrue(friend2 instanceof TestBean);
+
+ assertNotSame(jenny1, jenny2);
+ assertNotSame(friend1, friend2);
}
@Test
diff --git a/src/docs/asciidoc/core/core-beans.adoc b/src/docs/asciidoc/core/core-beans.adoc
index b8651e2878d..a62cde70038 100644
--- a/src/docs/asciidoc/core/core-beans.adoc
+++ b/src/docs/asciidoc/core/core-beans.adoc
@@ -5710,10 +5710,10 @@ Spring stereotype annotation (`@Component`, `@Repository`, `@Service`, and
`@Controller`) that contains a _name_ `value` will thereby provide that name to the
corresponding bean definition.
-If such an annotation contains no _name_ `value` or for any other detected component (such
-as those discovered by custom filters), the default bean name generator returns the
-uncapitalized non-qualified class name. For example, if the following two components
-were detected, the names would be `myMovieLister` and `movieFinderImpl`:
+If such an annotation contains no _name_ `value` or for any other detected component
+(such as those discovered by custom filters), the default bean name generator returns
+the uncapitalized non-qualified class name. For example, if the following component
+classes were detected, the names would be `myMovieLister` and `movieFinderImpl`:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -5772,8 +5772,8 @@ auto-generated names are adequate whenever the container is responsible for wiri
As with Spring-managed components in general, the default and most common scope for
autodetected components is `singleton`. However, sometimes you need a different scope
-which can be specified via the `@Scope` annotation. Simply provide the name of the scope
-within the annotation:
+which can be specified via the `@Scope` annotation. Simply provide the name of the
+scope within the annotation:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -5785,8 +5785,19 @@ within the annotation:
}
----
-For details on web-specific scopes, see <