Allow chained BeanRegistry registration
Add a `register(BeanRegistry registry)` method to `BeanRegistry` to allow registration chaining. See gh-34557
This commit is contained in:
committed by
Sébastien Deleuze
parent
a0e2d3a221
commit
789791e186
@@ -79,6 +79,13 @@ public interface BeanRegistry {
|
||||
*/
|
||||
<T> void registerBean(String name, Class<T> beanClass, Consumer<Spec<T>> customizer);
|
||||
|
||||
/**
|
||||
* Register beans using given {@link BeanRegistrar}.
|
||||
* @param registrar the bean registrar that will be called to register
|
||||
* additional beans
|
||||
*/
|
||||
void register(BeanRegistrar registrar);
|
||||
|
||||
/**
|
||||
* Specification for customizing a bean.
|
||||
* @param <T> the bean type
|
||||
|
||||
@@ -32,6 +32,8 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionCustomizer;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
@@ -47,21 +49,26 @@ public class BeanRegistryAdapter implements BeanRegistry {
|
||||
|
||||
private final ListableBeanFactory beanFactory;
|
||||
|
||||
private final Environment environment;
|
||||
|
||||
private final Class<? extends BeanRegistrar> beanRegistrarClass;
|
||||
|
||||
private final @Nullable MultiValueMap<String, BeanDefinitionCustomizer> customizers;
|
||||
|
||||
|
||||
public BeanRegistryAdapter(BeanDefinitionRegistry beanRegistry, ListableBeanFactory beanFactory,
|
||||
Class<? extends BeanRegistrar> beanRegistrarClass) {
|
||||
this(beanRegistry, beanFactory, beanRegistrarClass, null);
|
||||
Environment environment, Class<? extends BeanRegistrar> beanRegistrarClass) {
|
||||
|
||||
this(beanRegistry, beanFactory, environment, beanRegistrarClass, null);
|
||||
}
|
||||
|
||||
public BeanRegistryAdapter(BeanDefinitionRegistry beanRegistry, ListableBeanFactory beanFactory,
|
||||
Class<? extends BeanRegistrar> beanRegistrarClass, @Nullable MultiValueMap<String, BeanDefinitionCustomizer> customizers) {
|
||||
Environment environment, Class<? extends BeanRegistrar> beanRegistrarClass,
|
||||
@Nullable MultiValueMap<String, BeanDefinitionCustomizer> customizers) {
|
||||
|
||||
this.beanRegistry = beanRegistry;
|
||||
this.beanFactory = beanFactory;
|
||||
this.environment = environment;
|
||||
this.beanRegistrarClass = beanRegistrarClass;
|
||||
this.customizers = customizers;
|
||||
}
|
||||
@@ -103,6 +110,12 @@ public class BeanRegistryAdapter implements BeanRegistry {
|
||||
this.beanRegistry.registerBeanDefinition(name, beanDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(BeanRegistrar registrar) {
|
||||
Assert.notNull(registrar, "'registrar' must not be null");
|
||||
registrar.register(this, this.environment);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link RootBeanDefinition} subclass for {@code #registerBean} based
|
||||
|
||||
Reference in New Issue
Block a user