Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f05b462

Browse files
committed
Merge branch '5.1.x'
2 parents e93ac7a + 7d126d3 commit f05b462

File tree

11 files changed

+193
-174
lines changed

11 files changed

+193
-174
lines changed

spring-context/src/main/java/org/springframework/context/annotation/AnnotatedBeanDefinitionReader.java

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
import org.springframework.util.Assert;
3535

3636
/**
37-
* Convenient adapter for programmatic registration of annotated bean classes.
38-
* This is an alternative to {@link ClassPathBeanDefinitionScanner}, applying
37+
* Convenient adapter for programmatic registration of bean classes.
38+
*
39+
* <p>This is an alternative to {@link ClassPathBeanDefinitionScanner}, applying
3940
* the same resolution of annotations but for explicitly registered classes only.
4041
*
4142
* @author Juergen Hoeller
@@ -58,7 +59,7 @@ public class AnnotatedBeanDefinitionReader {
5859

5960
/**
6061
* Create a new {@code AnnotatedBeanDefinitionReader} for the given registry.
61-
* If the registry is {@link EnvironmentCapable}, e.g. is an {@code ApplicationContext},
62+
* <p>If the registry is {@link EnvironmentCapable}, e.g. is an {@code ApplicationContext},
6263
* the {@link Environment} will be inherited, otherwise a new
6364
* {@link StandardEnvironment} will be created and used.
6465
* @param registry the {@code BeanFactory} to load bean definitions into,
@@ -71,8 +72,8 @@ public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry) {
7172
}
7273

7374
/**
74-
* Create a new {@code AnnotatedBeanDefinitionReader} for the given registry and using
75-
* the given {@link Environment}.
75+
* Create a new {@code AnnotatedBeanDefinitionReader} for the given registry,
76+
* using the given {@link Environment}.
7677
* @param registry the {@code BeanFactory} to load bean definitions into,
7778
* in the form of a {@code BeanDefinitionRegistry}
7879
* @param environment the {@code Environment} to use when evaluating bean definition
@@ -89,14 +90,14 @@ public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environmen
8990

9091

9192
/**
92-
* Return the BeanDefinitionRegistry that this scanner operates on.
93+
* Get the BeanDefinitionRegistry that this reader operates on.
9394
*/
9495
public final BeanDefinitionRegistry getRegistry() {
9596
return this.registry;
9697
}
9798

9899
/**
99-
* Set the Environment to use when evaluating whether
100+
* Set the {@code Environment} to use when evaluating whether
100101
* {@link Conditional @Conditional}-annotated component classes should be registered.
101102
* <p>The default is a {@link StandardEnvironment}.
102103
* @see #registerBean(Class, String, Class...)
@@ -106,7 +107,7 @@ public void setEnvironment(Environment environment) {
106107
}
107108

108109
/**
109-
* Set the BeanNameGenerator to use for detected bean classes.
110+
* Set the {@code BeanNameGenerator} to use for detected bean classes.
110111
* <p>The default is a {@link AnnotationBeanNameGenerator}.
111112
*/
112113
public void setBeanNameGenerator(@Nullable BeanNameGenerator beanNameGenerator) {
@@ -115,7 +116,7 @@ public void setBeanNameGenerator(@Nullable BeanNameGenerator beanNameGenerator)
115116
}
116117

117118
/**
118-
* Set the ScopeMetadataResolver to use for detected bean classes.
119+
* Set the {@code ScopeMetadataResolver} to use for registered component classes.
119120
* <p>The default is an {@link AnnotationScopeMetadataResolver}.
120121
*/
121122
public void setScopeMetadataResolver(@Nullable ScopeMetadataResolver scopeMetadataResolver) {
@@ -125,99 +126,99 @@ public void setScopeMetadataResolver(@Nullable ScopeMetadataResolver scopeMetada
125126

126127

127128
/**
128-
* Register one or more annotated classes to be processed.
129+
* Register one or more component classes to be processed.
129130
* <p>Calls to {@code register} are idempotent; adding the same
130-
* annotated class more than once has no additional effect.
131-
* @param annotatedClasses one or more annotated classes,
131+
* component class more than once has no additional effect.
132+
* @param componentClasses one or more component classes,
132133
* e.g. {@link Configuration @Configuration} classes
133134
*/
134-
public void register(Class<?>... annotatedClasses) {
135-
for (Class<?> annotatedClass : annotatedClasses) {
136-
registerBean(annotatedClass);
135+
public void register(Class<?>... componentClasses) {
136+
for (Class<?> componentClass : componentClasses) {
137+
registerBean(componentClass);
137138
}
138139
}
139140

140141
/**
141142
* Register a bean from the given bean class, deriving its metadata from
142143
* class-declared annotations.
143-
* @param annotatedClass the class of the bean
144+
* @param beanClass the class of the bean
144145
*/
145-
public void registerBean(Class<?> annotatedClass) {
146-
doRegisterBean(annotatedClass, null, null, null, null);
146+
public void registerBean(Class<?> beanClass) {
147+
doRegisterBean(beanClass, null, null, null, null);
147148
}
148149

149150
/**
150151
* Register a bean from the given bean class, deriving its metadata from
151152
* class-declared annotations.
152-
* @param annotatedClass the class of the bean
153+
* @param beanClass the class of the bean
153154
* @param name an explicit name for the bean
154155
* (or {@code null} for generating a default bean name)
155156
* @since 5.2
156157
*/
157-
public void registerBean(Class<?> annotatedClass, @Nullable String name) {
158-
doRegisterBean(annotatedClass, name, null, null, null);
158+
public void registerBean(Class<?> beanClass, @Nullable String name) {
159+
doRegisterBean(beanClass, name, null, null, null);
159160
}
160161

161162
/**
162163
* Register a bean from the given bean class, deriving its metadata from
163164
* class-declared annotations.
164-
* @param annotatedClass the class of the bean
165+
* @param beanClass the class of the bean
165166
* @param qualifiers specific qualifier annotations to consider,
166167
* in addition to qualifiers at the bean class level
167168
*/
168169
@SuppressWarnings("unchecked")
169-
public void registerBean(Class<?> annotatedClass, Class<? extends Annotation>... qualifiers) {
170-
doRegisterBean(annotatedClass, null, qualifiers, null, null);
170+
public void registerBean(Class<?> beanClass, Class<? extends Annotation>... qualifiers) {
171+
doRegisterBean(beanClass, null, qualifiers, null, null);
171172
}
172173

173174
/**
174175
* Register a bean from the given bean class, deriving its metadata from
175176
* class-declared annotations.
176-
* @param annotatedClass the class of the bean
177+
* @param beanClass the class of the bean
177178
* @param name an explicit name for the bean
178179
* (or {@code null} for generating a default bean name)
179180
* @param qualifiers specific qualifier annotations to consider,
180181
* in addition to qualifiers at the bean class level
181182
*/
182183
@SuppressWarnings("unchecked")
183-
public void registerBean(Class<?> annotatedClass, @Nullable String name,
184+
public void registerBean(Class<?> beanClass, @Nullable String name,
184185
Class<? extends Annotation>... qualifiers) {
185186

186-
doRegisterBean(annotatedClass, name, qualifiers, null, null);
187+
doRegisterBean(beanClass, name, qualifiers, null, null);
187188
}
188189

189190
/**
190191
* Register a bean from the given bean class, deriving its metadata from
191192
* class-declared annotations, using the given supplier for obtaining a new
192193
* instance (possibly declared as a lambda expression or method reference).
193-
* @param annotatedClass the class of the bean
194+
* @param beanClass the class of the bean
194195
* @param supplier a callback for creating an instance of the bean
195196
* (may be {@code null})
196197
* @since 5.0
197198
*/
198-
public <T> void registerBean(Class<T> annotatedClass, @Nullable Supplier<T> supplier) {
199-
doRegisterBean(annotatedClass, null, null, supplier, null);
199+
public <T> void registerBean(Class<T> beanClass, @Nullable Supplier<T> supplier) {
200+
doRegisterBean(beanClass, null, null, supplier, null);
200201
}
201202

202203
/**
203204
* Register a bean from the given bean class, deriving its metadata from
204205
* class-declared annotations, using the given supplier for obtaining a new
205206
* instance (possibly declared as a lambda expression or method reference).
206-
* @param annotatedClass the class of the bean
207+
* @param beanClass the class of the bean
207208
* @param name an explicit name for the bean
208209
* (or {@code null} for generating a default bean name)
209210
* @param supplier a callback for creating an instance of the bean
210211
* (may be {@code null})
211212
* @since 5.0
212213
*/
213-
public <T> void registerBean(Class<T> annotatedClass, @Nullable String name, @Nullable Supplier<T> supplier) {
214-
doRegisterBean(annotatedClass, name, null, supplier, null);
214+
public <T> void registerBean(Class<T> beanClass, @Nullable String name, @Nullable Supplier<T> supplier) {
215+
doRegisterBean(beanClass, name, null, supplier, null);
215216
}
216217

217218
/**
218219
* Register a bean from the given bean class, deriving its metadata from
219220
* class-declared annotations.
220-
* @param annotatedClass the class of the bean
221+
* @param beanClass the class of the bean
221222
* @param name an explicit name for the bean
222223
* (or {@code null} for generating a default bean name)
223224
* @param supplier a callback for creating an instance of the bean
@@ -226,16 +227,16 @@ public <T> void registerBean(Class<T> annotatedClass, @Nullable String name, @Nu
226227
* {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
227228
* @since 5.2
228229
*/
229-
public <T> void registerBean(Class<T> annotatedClass, @Nullable String name, @Nullable Supplier<T> supplier,
230+
public <T> void registerBean(Class<T> beanClass, @Nullable String name, @Nullable Supplier<T> supplier,
230231
BeanDefinitionCustomizer... customizers) {
231232

232-
doRegisterBean(annotatedClass, name, null, supplier, customizers);
233+
doRegisterBean(beanClass, name, null, supplier, customizers);
233234
}
234235

235236
/**
236237
* Register a bean from the given bean class, deriving its metadata from
237238
* class-declared annotations.
238-
* @param annotatedClass the class of the bean
239+
* @param beanClass the class of the bean
239240
* @param name an explicit name for the bean
240241
* @param supplier a callback for creating an instance of the bean
241242
* (may be {@code null})
@@ -245,11 +246,11 @@ public <T> void registerBean(Class<T> annotatedClass, @Nullable String name, @Nu
245246
* {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
246247
* @since 5.0
247248
*/
248-
private <T> void doRegisterBean(Class<T> annotatedClass, @Nullable String name,
249+
private <T> void doRegisterBean(Class<T> beanClass, @Nullable String name,
249250
@Nullable Class<? extends Annotation>[] qualifiers, @Nullable Supplier<T> supplier,
250251
@Nullable BeanDefinitionCustomizer[] customizers) {
251252

252-
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
253+
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(beanClass);
253254
if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
254255
return;
255256
}

spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@
2727
import org.springframework.util.Assert;
2828

2929
/**
30-
* Standalone application context, accepting annotated classes as input - in particular
31-
* {@link Configuration @Configuration}-annotated classes, but also plain
30+
* Standalone application context, accepting <em>component classes</em> as input &mdash;
31+
* in particular {@link Configuration @Configuration}-annotated classes, but also plain
3232
* {@link org.springframework.stereotype.Component @Component} types and JSR-330 compliant
33-
* classes using {@code javax.inject} annotations. Allows for registering classes one by
34-
* one using {@link #register(Class...)} as well as for classpath scanning using
35-
* {@link #scan(String...)}.
33+
* classes using {@code javax.inject} annotations.
3634
*
37-
* <p>In case of multiple {@code @Configuration} classes, @{@link Bean} methods defined in
38-
* later classes will override those defined in earlier classes. This can be leveraged to
39-
* deliberately override certain bean definitions via an extra {@code @Configuration}
40-
* class.
35+
* <p>Allows for registering classes one by one using {@link #register(Class...)}
36+
* as well as for classpath scanning using {@link #scan(String...)}.
4137
*
42-
* <p>See @{@link Configuration}'s javadoc for usage examples.
38+
* <p>In case of multiple {@code @Configuration} classes, {@link Bean @Bean} methods
39+
* defined in later classes will override those defined in earlier classes. This can
40+
* be leveraged to deliberately override certain bean definitions via an extra
41+
* {@code @Configuration} class.
42+
*
43+
* <p>See {@link Configuration @Configuration}'s javadoc for usage examples.
4344
*
4445
* @author Juergen Hoeller
4546
* @author Chris Beams
@@ -78,20 +79,21 @@ public AnnotationConfigApplicationContext(DefaultListableBeanFactory beanFactory
7879

7980
/**
8081
* Create a new AnnotationConfigApplicationContext, deriving bean definitions
81-
* from the given annotated classes and automatically refreshing the context.
82-
* @param annotatedClasses one or more annotated classes,
83-
* e.g. {@link Configuration @Configuration} classes
82+
* from the given component classes and automatically refreshing the context.
83+
* @param componentClasses one or more component classes &mdash; for example,
84+
* {@link Configuration @Configuration} classes
8485
*/
85-
public AnnotationConfigApplicationContext(Class<?>... annotatedClasses) {
86+
public AnnotationConfigApplicationContext(Class<?>... componentClasses) {
8687
this();
87-
register(annotatedClasses);
88+
register(componentClasses);
8889
refresh();
8990
}
9091

9192
/**
92-
* Create a new AnnotationConfigApplicationContext, scanning for bean definitions
93-
* in the given packages and automatically refreshing the context.
94-
* @param basePackages the packages to check for annotated classes
93+
* Create a new AnnotationConfigApplicationContext, scanning for components
94+
* in the given packages, registering bean definitions for those components,
95+
* and automatically refreshing the context.
96+
* @param basePackages the packages to scan for component classes
9597
*/
9698
public AnnotationConfigApplicationContext(String... basePackages) {
9799
this();
@@ -101,7 +103,7 @@ public AnnotationConfigApplicationContext(String... basePackages) {
101103

102104

103105
/**
104-
* Propagates the given custom {@code Environment} to the underlying
106+
* Propagate the given custom {@code Environment} to the underlying
105107
* {@link AnnotatedBeanDefinitionReader} and {@link ClassPathBeanDefinitionScanner}.
106108
*/
107109
@Override
@@ -128,7 +130,7 @@ public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
128130
}
129131

130132
/**
131-
* Set the {@link ScopeMetadataResolver} to use for detected bean classes.
133+
* Set the {@link ScopeMetadataResolver} to use for registered component classes.
132134
* <p>The default is an {@link AnnotationScopeMetadataResolver}.
133135
* <p>Any call to this method must occur prior to calls to {@link #register(Class...)}
134136
* and/or {@link #scan(String...)}.
@@ -144,25 +146,25 @@ public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver
144146
//---------------------------------------------------------------------
145147

146148
/**
147-
* Register one or more annotated classes to be processed.
149+
* Register one or more component classes to be processed.
148150
* <p>Note that {@link #refresh()} must be called in order for the context
149151
* to fully process the new classes.
150-
* @param annotatedClasses one or more annotated classes,
151-
* e.g. {@link Configuration @Configuration} classes
152+
* @param componentClasses one or more component classes &mdash; for example,
153+
* {@link Configuration @Configuration} classes
152154
* @see #scan(String...)
153155
* @see #refresh()
154156
*/
155157
@Override
156-
public void register(Class<?>... annotatedClasses) {
157-
Assert.notEmpty(annotatedClasses, "At least one annotated class must be specified");
158-
this.reader.register(annotatedClasses);
158+
public void register(Class<?>... componentClasses) {
159+
Assert.notEmpty(componentClasses, "At least one component class must be specified");
160+
this.reader.register(componentClasses);
159161
}
160162

161163
/**
162164
* Perform a scan within the specified base packages.
163165
* <p>Note that {@link #refresh()} must be called in order for the context
164166
* to fully process the new classes.
165-
* @param basePackages the packages to check for annotated classes
167+
* @param basePackages the packages to scan for component classes
166168
* @see #register(Class...)
167169
* @see #refresh()
168170
*/

spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigRegistry.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,17 +26,17 @@
2626
public interface AnnotationConfigRegistry {
2727

2828
/**
29-
* Register one or more annotated classes to be processed.
29+
* Register one or more component classes to be processed.
3030
* <p>Calls to {@code register} are idempotent; adding the same
31-
* annotated class more than once has no additional effect.
32-
* @param annotatedClasses one or more annotated classes,
31+
* component class more than once has no additional effect.
32+
* @param componentClasses one or more component classes,
3333
* e.g. {@link Configuration @Configuration} classes
3434
*/
35-
void register(Class<?>... annotatedClasses);
35+
void register(Class<?>... componentClasses);
3636

3737
/**
3838
* Perform a scan within the specified base packages.
39-
* @param basePackages the packages to check for annotated classes
39+
* @param basePackages the packages to scan for component classes
4040
*/
4141
void scan(String... basePackages);
4242

spring-context/src/main/java/org/springframework/context/annotation/Configuration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@
352352
*
353353
* <p>The Spring <em>TestContext framework</em> available in the {@code spring-test} module
354354
* provides the {@code @ContextConfiguration} annotation which can accept an array of
355-
* {@code @Configuration} {@code Class} objects:
355+
* <em>component class</em> references &mdash; typically {@code @Configuration} or
356+
* {@code @Component} classes.
356357
*
357358
* <pre class="code">
358359
* &#064;RunWith(SpringRunner.class)

0 commit comments

Comments
 (0)