1616
1717package org .springframework .boot .web .reactive .context ;
1818
19- import java .lang .annotation .Annotation ;
2019import java .util .Arrays ;
2120import java .util .LinkedHashSet ;
2221import java .util .Set ;
23- import java .util .function .Supplier ;
2422
2523import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
2624import org .springframework .beans .factory .support .BeanNameGenerator ;
3735import org .springframework .util .Assert ;
3836import org .springframework .util .ClassUtils ;
3937import org .springframework .util .ObjectUtils ;
40- import org .springframework .util .StringUtils ;
4138
4239/**
4340 * {@link ReactiveWebServerApplicationContext} that accepts annotated classes as input -
@@ -70,8 +67,6 @@ public class AnnotationConfigReactiveWebServerApplicationContext
7067
7168 private String [] basePackages ;
7269
73- private final Set <BeanRegistration > registeredBeans = new LinkedHashSet <>();
74-
7570 /**
7671 * Create a new {@link AnnotationConfigReactiveWebServerApplicationContext} that needs
7772 * to be populated through {@link #register} calls and then manually
@@ -202,45 +197,6 @@ public final void scan(String... basePackages) {
202197 this .basePackages = basePackages ;
203198 }
204199
205- /**
206- * Register a bean from the given bean class.
207- * @param annotatedClass the class of the bean
208- * @param <T> the type of the bean
209- * @since 2.2.0
210- */
211- public final <T > void registerBean (Class <T > annotatedClass ) {
212- this .registeredBeans .add (new BeanRegistration (annotatedClass , null , null ));
213- }
214-
215- /**
216- * Register a bean from the given bean class, using the given supplier for obtaining a
217- * new instance (typically declared as a lambda expression or method reference).
218- * @param annotatedClass the class of the bean
219- * @param supplier a callback for creating an instance of the bean
220- * @param <T> the type of the bean
221- * @since 2.2.0
222- */
223- public final <T > void registerBean (Class <T > annotatedClass , Supplier <T > supplier ) {
224- this .registeredBeans .add (new BeanRegistration (annotatedClass , supplier , null ));
225- }
226-
227- @ Override
228- @ SafeVarargs
229- @ SuppressWarnings ("varargs" )
230- public final <T > void registerBean (Class <T > annotatedClass ,
231- Class <? extends Annotation >... qualifiers ) {
232- this .registeredBeans .add (new BeanRegistration (annotatedClass , null , qualifiers ));
233- }
234-
235- @ Override
236- @ SafeVarargs
237- @ SuppressWarnings ("varargs" )
238- public final <T > void registerBean (Class <T > annotatedClass , Supplier <T > supplier ,
239- Class <? extends Annotation >... qualifiers ) {
240- this .registeredBeans
241- .add (new BeanRegistration (annotatedClass , supplier , qualifiers ));
242- }
243-
244200 @ Override
245201 protected void prepareRefresh () {
246202 this .scanner .clearCache ();
@@ -256,60 +212,6 @@ protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactor
256212 if (!this .annotatedClasses .isEmpty ()) {
257213 this .reader .register (ClassUtils .toClassArray (this .annotatedClasses ));
258214 }
259- if (!this .registeredBeans .isEmpty ()) {
260- registerBeans (this .reader );
261- }
262- }
263-
264- private void registerBeans (AnnotatedBeanDefinitionReader reader ) {
265- if (this .logger .isDebugEnabled ()) {
266- this .logger .debug ("Registering supplied beans: ["
267- + StringUtils .collectionToCommaDelimitedString (this .registeredBeans )
268- + "]" );
269- }
270- this .registeredBeans .forEach ((reg ) -> reader .registerBean (reg .getAnnotatedClass (),
271- reg .getSupplier (), reg .getQualifiers ()));
272- }
273-
274- /**
275- * Holder for a programmatic bean registration.
276- *
277- * @see #registerBean(Class, Class[])
278- * @see #registerBean(Class, Supplier, Class[])
279- */
280- private static class BeanRegistration {
281-
282- private final Class <?> annotatedClass ;
283-
284- private final Supplier <?> supplier ;
285-
286- private final Class <? extends Annotation >[] qualifiers ;
287-
288- BeanRegistration (Class <?> annotatedClass , Supplier <?> supplier ,
289- Class <? extends Annotation >[] qualifiers ) {
290- this .annotatedClass = annotatedClass ;
291- this .supplier = supplier ;
292- this .qualifiers = qualifiers ;
293- }
294-
295- public Class <?> getAnnotatedClass () {
296- return this .annotatedClass ;
297- }
298-
299- @ SuppressWarnings ("rawtypes" )
300- public Supplier getSupplier () {
301- return this .supplier ;
302- }
303-
304- public Class <? extends Annotation >[] getQualifiers () {
305- return this .qualifiers ;
306- }
307-
308- @ Override
309- public String toString () {
310- return this .annotatedClass .getName ();
311- }
312-
313215 }
314216
315217}
0 commit comments