Polishing

This commit is contained in:
Juergen Hoeller
2026-03-28 20:38:03 +01:00
parent f0f447a73d
commit 0abf97ff90
9 changed files with 22 additions and 14 deletions
@@ -25,6 +25,7 @@ import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanRegistrar;
import org.springframework.beans.factory.BeanRegistry;
import org.springframework.beans.factory.ListableBeanFactory;
@@ -81,6 +82,12 @@ public class BeanRegistryAdapter implements BeanRegistry {
}
@Override
public void register(BeanRegistrar registrar) {
Assert.notNull(registrar, "BeanRegistrar must not be null");
registrar.register(this, this.environment);
}
@Override
public void registerAlias(String name, String alias) {
this.beanRegistry.registerAlias(name, alias);
@@ -169,12 +176,6 @@ 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
@@ -218,9 +219,9 @@ public class BeanRegistryAdapter implements BeanRegistry {
private final RootBeanDefinition beanDefinition;
private final ListableBeanFactory beanFactory;
private final BeanFactory beanFactory;
public BeanSpecAdapter(RootBeanDefinition beanDefinition, ListableBeanFactory beanFactory) {
public BeanSpecAdapter(RootBeanDefinition beanDefinition, BeanFactory beanFactory) {
this.beanDefinition = beanDefinition;
this.beanFactory = beanFactory;
}
@@ -296,9 +297,9 @@ public class BeanRegistryAdapter implements BeanRegistry {
private static class SupplierContextAdapter implements SupplierContext {
private final ListableBeanFactory beanFactory;
private final BeanFactory beanFactory;
public SupplierContextAdapter(ListableBeanFactory beanFactory) {
public SupplierContextAdapter(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
@@ -222,7 +222,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
/**
* Set the {@link ProblemReporter} to use.
* <p>Used to register any problems detected with {@link Configuration} or {@link Bean}
* declarations. For instance, an @Bean method marked as {@code final} is illegal
* declarations. For instance, a @Bean method marked as {@code final} is illegal
* and would be reported as a problem. Defaults to {@link FailFastProblemReporter}.
*/
public void setProblemReporter(@Nullable ProblemReporter problemReporter) {
@@ -71,8 +71,8 @@ public @interface Import {
/**
* {@link Configuration @Configuration}, {@link ImportSelector},
* {@link ImportBeanDefinitionRegistrar}, {@link BeanRegistrar}, or regular
* component classes to import.
* {@link ImportBeanDefinitionRegistrar}, {@link BeanRegistrar},
* or regular component classes to import.
*/
Class<?>[] value();
@@ -795,7 +795,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(beanFactory, getBeanFactoryPostProcessors());
// Detect a LoadTimeWeaver and prepare for weaving, if found in the meantime
// (for example, through an @Bean method registered by ConfigurationClassPostProcessor)
// (for example, through a @Bean method registered by ConfigurationClassPostProcessor)
if (!NativeDetector.inNativeImage() && beanFactory.getTempClassLoader() == null &&
beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) {
beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory));
@@ -28,4 +28,5 @@ public class BarRegistrar implements BeanRegistrar {
}
public record Bar() {}
}
@@ -28,4 +28,5 @@ public class FooRegistrar implements BeanRegistrar {
}
public record Foo() {}
}
@@ -32,4 +32,5 @@ public class GenericBeanRegistrar implements BeanRegistrar {
}
public record Foo() {}
}
@@ -45,4 +45,5 @@ public class ImportAwareBeanRegistrar implements BeanRegistrar, ImportAware {
}
public record ClassNameHolder(@Nullable String className) {}
}
@@ -41,7 +41,9 @@ public class SampleBeanRegistrar implements BeanRegistrar {
}
public record Foo() {}
public record Bar(Foo foo) {}
public record Baz(String message) {}
public static class Init {
@@ -53,4 +55,5 @@ public class SampleBeanRegistrar implements BeanRegistrar {
initialized = true;
}
}
}