Browse Source

Polishing

pull/36577/head
Juergen Hoeller 2 weeks ago
parent
commit
0abf97ff90
  1. 21
      spring-beans/src/main/java/org/springframework/beans/factory/support/BeanRegistryAdapter.java
  2. 2
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java
  3. 4
      spring-context/src/main/java/org/springframework/context/annotation/Import.java
  4. 2
      spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java
  5. 1
      spring-context/src/testFixtures/java/org/springframework/context/testfixture/beans/factory/BarRegistrar.java
  6. 1
      spring-context/src/testFixtures/java/org/springframework/context/testfixture/beans/factory/FooRegistrar.java
  7. 1
      spring-context/src/testFixtures/java/org/springframework/context/testfixture/beans/factory/GenericBeanRegistrar.java
  8. 1
      spring-context/src/testFixtures/java/org/springframework/context/testfixture/beans/factory/ImportAwareBeanRegistrar.java
  9. 3
      spring-context/src/testFixtures/java/org/springframework/context/testfixture/beans/factory/SampleBeanRegistrar.java

21
spring-beans/src/main/java/org/springframework/beans/factory/support/BeanRegistryAdapter.java

@ -25,6 +25,7 @@ import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanRegistrar; import org.springframework.beans.factory.BeanRegistrar;
import org.springframework.beans.factory.BeanRegistry; import org.springframework.beans.factory.BeanRegistry;
import org.springframework.beans.factory.ListableBeanFactory; 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 @Override
public void registerAlias(String name, String alias) { public void registerAlias(String name, String alias) {
this.beanRegistry.registerAlias(name, alias); this.beanRegistry.registerAlias(name, alias);
@ -169,12 +176,6 @@ public class BeanRegistryAdapter implements BeanRegistry {
this.beanRegistry.registerBeanDefinition(name, beanDefinition); 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 * {@link RootBeanDefinition} subclass for {@code #registerBean} based
@ -218,9 +219,9 @@ public class BeanRegistryAdapter implements BeanRegistry {
private final RootBeanDefinition beanDefinition; 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.beanDefinition = beanDefinition;
this.beanFactory = beanFactory; this.beanFactory = beanFactory;
} }
@ -296,9 +297,9 @@ public class BeanRegistryAdapter implements BeanRegistry {
private static class SupplierContextAdapter implements SupplierContext { 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; this.beanFactory = beanFactory;
} }

2
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

@ -222,7 +222,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
/** /**
* Set the {@link ProblemReporter} to use. * Set the {@link ProblemReporter} to use.
* <p>Used to register any problems detected with {@link Configuration} or {@link Bean} * <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}. * and would be reported as a problem. Defaults to {@link FailFastProblemReporter}.
*/ */
public void setProblemReporter(@Nullable ProblemReporter problemReporter) { public void setProblemReporter(@Nullable ProblemReporter problemReporter) {

4
spring-context/src/main/java/org/springframework/context/annotation/Import.java

@ -71,8 +71,8 @@ public @interface Import {
/** /**
* {@link Configuration @Configuration}, {@link ImportSelector}, * {@link Configuration @Configuration}, {@link ImportSelector},
* {@link ImportBeanDefinitionRegistrar}, {@link BeanRegistrar}, or regular * {@link ImportBeanDefinitionRegistrar}, {@link BeanRegistrar},
* component classes to import. * or regular component classes to import.
*/ */
Class<?>[] value(); Class<?>[] value();

2
spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

@ -795,7 +795,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(beanFactory, getBeanFactoryPostProcessors()); PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(beanFactory, getBeanFactoryPostProcessors());
// Detect a LoadTimeWeaver and prepare for weaving, if found in the meantime // 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 && if (!NativeDetector.inNativeImage() && beanFactory.getTempClassLoader() == null &&
beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) { beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) {
beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory)); beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory));

1
spring-context/src/testFixtures/java/org/springframework/context/testfixture/beans/factory/BarRegistrar.java

@ -28,4 +28,5 @@ public class BarRegistrar implements BeanRegistrar {
} }
public record Bar() {} public record Bar() {}
} }

1
spring-context/src/testFixtures/java/org/springframework/context/testfixture/beans/factory/FooRegistrar.java

@ -28,4 +28,5 @@ public class FooRegistrar implements BeanRegistrar {
} }
public record Foo() {} public record Foo() {}
} }

1
spring-context/src/testFixtures/java/org/springframework/context/testfixture/beans/factory/GenericBeanRegistrar.java

@ -32,4 +32,5 @@ public class GenericBeanRegistrar implements BeanRegistrar {
} }
public record Foo() {} public record Foo() {}
} }

1
spring-context/src/testFixtures/java/org/springframework/context/testfixture/beans/factory/ImportAwareBeanRegistrar.java

@ -45,4 +45,5 @@ public class ImportAwareBeanRegistrar implements BeanRegistrar, ImportAware {
} }
public record ClassNameHolder(@Nullable String className) {} public record ClassNameHolder(@Nullable String className) {}
} }

3
spring-context/src/testFixtures/java/org/springframework/context/testfixture/beans/factory/SampleBeanRegistrar.java

@ -41,7 +41,9 @@ public class SampleBeanRegistrar implements BeanRegistrar {
} }
public record Foo() {} public record Foo() {}
public record Bar(Foo foo) {} public record Bar(Foo foo) {}
public record Baz(String message) {} public record Baz(String message) {}
public static class Init { public static class Init {
@ -53,4 +55,5 @@ public class SampleBeanRegistrar implements BeanRegistrar {
initialized = true; initialized = true;
} }
} }
} }

Loading…
Cancel
Save