@@ -143,34 +143,19 @@ public void register(Class<?>... annotatedClasses) {
143
143
* @param annotatedClass the class of the bean
144
144
*/
145
145
public void registerBean (Class <?> annotatedClass ) {
146
- doRegisterBean (annotatedClass , null , null , null );
146
+ doRegisterBean (annotatedClass , null , null , null , null );
147
147
}
148
148
149
149
/**
150
150
* Register a bean from the given bean class, deriving its metadata from
151
- * class-declared annotations, using the given supplier for obtaining a new
152
- * instance (possibly declared as a lambda expression or method reference).
153
- * @param annotatedClass the class of the bean
154
- * @param instanceSupplier a callback for creating an instance of the bean
155
- * (may be {@code null})
156
- * @since 5.0
157
- */
158
- public <T > void registerBean (Class <T > annotatedClass , @ Nullable Supplier <T > instanceSupplier ) {
159
- doRegisterBean (annotatedClass , instanceSupplier , null , null );
160
- }
161
-
162
- /**
163
- * Register a bean from the given bean class, deriving its metadata from
164
- * class-declared annotations, using the given supplier for obtaining a new
165
- * instance (possibly declared as a lambda expression or method reference).
151
+ * class-declared annotations.
166
152
* @param annotatedClass the class of the bean
167
153
* @param name an explicit name for the bean
168
- * @param instanceSupplier a callback for creating an instance of the bean
169
- * (may be {@code null})
170
- * @since 5.0
154
+ * (or {@code null} for generating a default bean name)
155
+ * @since 5.2
171
156
*/
172
- public < T > void registerBean (Class <T > annotatedClass , String name , @ Nullable Supplier < T > instanceSupplier ) {
173
- doRegisterBean (annotatedClass , instanceSupplier , name , null );
157
+ public void registerBean (Class <? > annotatedClass , @ Nullable String name ) {
158
+ doRegisterBean (annotatedClass , name , null , null , null );
174
159
}
175
160
176
161
/**
@@ -182,44 +167,94 @@ public <T> void registerBean(Class<T> annotatedClass, String name, @Nullable Sup
182
167
*/
183
168
@ SuppressWarnings ("unchecked" )
184
169
public void registerBean (Class <?> annotatedClass , Class <? extends Annotation >... qualifiers ) {
185
- doRegisterBean (annotatedClass , null , null , qualifiers );
170
+ doRegisterBean (annotatedClass , null , qualifiers , null , null );
186
171
}
187
172
188
173
/**
189
174
* Register a bean from the given bean class, deriving its metadata from
190
175
* class-declared annotations.
191
176
* @param annotatedClass the class of the bean
192
177
* @param name an explicit name for the bean
178
+ * (or {@code null} for generating a default bean name)
193
179
* @param qualifiers specific qualifier annotations to consider,
194
180
* in addition to qualifiers at the bean class level
195
181
*/
196
182
@ SuppressWarnings ("unchecked" )
197
- public void registerBean (Class <?> annotatedClass , String name , Class <? extends Annotation >... qualifiers ) {
198
- doRegisterBean (annotatedClass , null , name , qualifiers );
183
+ public void registerBean (Class <?> annotatedClass , @ Nullable String name ,
184
+ Class <? extends Annotation >... qualifiers ) {
185
+
186
+ doRegisterBean (annotatedClass , name , qualifiers , null , null );
187
+ }
188
+
189
+ /**
190
+ * Register a bean from the given bean class, deriving its metadata from
191
+ * class-declared annotations, using the given supplier for obtaining a new
192
+ * instance (possibly declared as a lambda expression or method reference).
193
+ * @param annotatedClass the class of the bean
194
+ * @param supplier a callback for creating an instance of the bean
195
+ * (may be {@code null})
196
+ * @since 5.0
197
+ */
198
+ public <T > void registerBean (Class <T > annotatedClass , @ Nullable Supplier <T > supplier ) {
199
+ doRegisterBean (annotatedClass , null , null , supplier , null );
200
+ }
201
+
202
+ /**
203
+ * Register a bean from the given bean class, deriving its metadata from
204
+ * class-declared annotations, using the given supplier for obtaining a new
205
+ * instance (possibly declared as a lambda expression or method reference).
206
+ * @param annotatedClass the class of the bean
207
+ * @param name an explicit name for the bean
208
+ * (or {@code null} for generating a default bean name)
209
+ * @param supplier a callback for creating an instance of the bean
210
+ * (may be {@code null})
211
+ * @since 5.0
212
+ */
213
+ public <T > void registerBean (Class <T > annotatedClass , @ Nullable String name , @ Nullable Supplier <T > supplier ) {
214
+ doRegisterBean (annotatedClass , name , null , supplier , null );
199
215
}
200
216
201
217
/**
202
218
* Register a bean from the given bean class, deriving its metadata from
203
219
* class-declared annotations.
204
220
* @param annotatedClass the class of the bean
205
- * @param instanceSupplier a callback for creating an instance of the bean
221
+ * @param name an explicit name for the bean
222
+ * (or {@code null} for generating a default bean name)
223
+ * @param supplier a callback for creating an instance of the bean
206
224
* (may be {@code null})
225
+ * @param customizers one or more callbacks for customizing the factory's
226
+ * {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
227
+ * @since 5.2
228
+ */
229
+ public <T > void registerBean (Class <T > annotatedClass , @ Nullable String name , @ Nullable Supplier <T > supplier ,
230
+ BeanDefinitionCustomizer ... customizers ) {
231
+
232
+ doRegisterBean (annotatedClass , name , null , supplier , customizers );
233
+ }
234
+
235
+ /**
236
+ * Register a bean from the given bean class, deriving its metadata from
237
+ * class-declared annotations.
238
+ * @param annotatedClass the class of the bean
207
239
* @param name an explicit name for the bean
240
+ * @param supplier a callback for creating an instance of the bean
241
+ * (may be {@code null})
208
242
* @param qualifiers specific qualifier annotations to consider, if any,
209
243
* in addition to qualifiers at the bean class level
210
- * @param definitionCustomizers one or more callbacks for customizing the
211
- * factory's {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
244
+ * @param customizers one or more callbacks for customizing the factory's
245
+ * {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
212
246
* @since 5.0
213
247
*/
214
- <T > void doRegisterBean (Class <T > annotatedClass , @ Nullable Supplier <T > instanceSupplier , @ Nullable String name ,
215
- @ Nullable Class <? extends Annotation >[] qualifiers , BeanDefinitionCustomizer ... definitionCustomizers ) {
248
+ private <T > void doRegisterBean (Class <T > annotatedClass , @ Nullable String name ,
249
+ @ Nullable Class <? extends Annotation >[] qualifiers , @ Nullable Supplier <T > supplier ,
250
+ @ Nullable BeanDefinitionCustomizer [] customizers ) {
216
251
217
252
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition (annotatedClass );
218
253
if (this .conditionEvaluator .shouldSkip (abd .getMetadata ())) {
219
254
return ;
220
255
}
221
256
222
- abd .setInstanceSupplier (instanceSupplier );
257
+ abd .setInstanceSupplier (supplier );
223
258
ScopeMetadata scopeMetadata = this .scopeMetadataResolver .resolveScopeMetadata (abd );
224
259
abd .setScope (scopeMetadata .getScopeName ());
225
260
String beanName = (name != null ? name : this .beanNameGenerator .generateBeanName (abd , this .registry ));
@@ -238,8 +273,10 @@ else if (Lazy.class == qualifier) {
238
273
}
239
274
}
240
275
}
241
- for (BeanDefinitionCustomizer customizer : definitionCustomizers ) {
242
- customizer .customize (abd );
276
+ if (customizers != null ) {
277
+ for (BeanDefinitionCustomizer customizer : customizers ) {
278
+ customizer .customize (abd );
279
+ }
243
280
}
244
281
245
282
BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder (abd , beanName );
0 commit comments