diff --git a/module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/IntegrationAutoConfigurationScanRegistrar.java b/module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/IntegrationAutoConfigurationScanRegistrar.java index bc8132890ea..92d931dec16 100644 --- a/module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/IntegrationAutoConfigurationScanRegistrar.java +++ b/module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/IntegrationAutoConfigurationScanRegistrar.java @@ -19,9 +19,7 @@ package org.springframework.boot.integration.autoconfigure; import java.util.Collection; import java.util.Collections; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.boot.autoconfigure.AutoConfigurationPackages; import org.springframework.core.annotation.AnnotationAttributes; @@ -36,13 +34,11 @@ import org.springframework.integration.config.IntegrationComponentScanRegistrar; * @author Artem Bilan * @author Phillip Webb */ -class IntegrationAutoConfigurationScanRegistrar extends IntegrationComponentScanRegistrar implements BeanFactoryAware { +class IntegrationAutoConfigurationScanRegistrar extends IntegrationComponentScanRegistrar { - @SuppressWarnings("NullAway.Init") - private BeanFactory beanFactory; + private final BeanFactory beanFactory; - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + IntegrationAutoConfigurationScanRegistrar(BeanFactory beanFactory) { this.beanFactory = beanFactory; } diff --git a/module/spring-boot-validation/src/main/java/org/springframework/boot/validation/autoconfigure/PrimaryDefaultValidatorPostProcessor.java b/module/spring-boot-validation/src/main/java/org/springframework/boot/validation/autoconfigure/PrimaryDefaultValidatorPostProcessor.java index d7ec00615bc..426c37f3b66 100644 --- a/module/spring-boot-validation/src/main/java/org/springframework/boot/validation/autoconfigure/PrimaryDefaultValidatorPostProcessor.java +++ b/module/spring-boot-validation/src/main/java/org/springframework/boot/validation/autoconfigure/PrimaryDefaultValidatorPostProcessor.java @@ -18,9 +18,7 @@ package org.springframework.boot.validation.autoconfigure; import org.jspecify.annotations.Nullable; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; @@ -42,20 +40,18 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; * @author Matej Nedic * @author Andy Wilkinson */ -class PrimaryDefaultValidatorPostProcessor implements ImportBeanDefinitionRegistrar, BeanFactoryAware { +class PrimaryDefaultValidatorPostProcessor implements ImportBeanDefinitionRegistrar { /** * The bean name of the auto-configured Validator. */ private static final String VALIDATOR_BEAN_NAME = "defaultValidator"; - private @Nullable ConfigurableListableBeanFactory beanFactory; + private final @Nullable ConfigurableListableBeanFactory beanFactory; - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - if (beanFactory instanceof ConfigurableListableBeanFactory listableBeanFactory) { - this.beanFactory = listableBeanFactory; - } + PrimaryDefaultValidatorPostProcessor(BeanFactory beanFactory) { + this.beanFactory = (beanFactory instanceof ConfigurableListableBeanFactory listableBeanFactory) + ? listableBeanFactory : null; } @Override diff --git a/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/autoconfigure/reactive/ReactiveWebServerConfiguration.java b/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/autoconfigure/reactive/ReactiveWebServerConfiguration.java index 14938716e96..64dea47c1a6 100644 --- a/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/autoconfigure/reactive/ReactiveWebServerConfiguration.java +++ b/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/autoconfigure/reactive/ReactiveWebServerConfiguration.java @@ -18,9 +18,7 @@ package org.springframework.boot.web.server.autoconfigure.reactive; import org.jspecify.annotations.Nullable; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; @@ -68,15 +66,13 @@ public class ReactiveWebServerConfiguration { * Registers a {@link WebServerFactoryCustomizerBeanPostProcessor}. Registered via * {@link ImportBeanDefinitionRegistrar} for early registration. */ - static class BeanPostProcessorsRegistrar implements ImportBeanDefinitionRegistrar, BeanFactoryAware { + static class BeanPostProcessorsRegistrar implements ImportBeanDefinitionRegistrar { - private @Nullable ConfigurableListableBeanFactory beanFactory; + private final @Nullable ConfigurableListableBeanFactory beanFactory; - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - if (beanFactory instanceof ConfigurableListableBeanFactory listableBeanFactory) { - this.beanFactory = listableBeanFactory; - } + BeanPostProcessorsRegistrar(BeanFactory beanFactory) { + this.beanFactory = (beanFactory instanceof ConfigurableListableBeanFactory listableBeanFactory) + ? listableBeanFactory : null; } @Override diff --git a/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/autoconfigure/servlet/ServletWebServerConfiguration.java b/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/autoconfigure/servlet/ServletWebServerConfiguration.java index 088f134ace4..44651561c8e 100644 --- a/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/autoconfigure/servlet/ServletWebServerConfiguration.java +++ b/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/autoconfigure/servlet/ServletWebServerConfiguration.java @@ -19,9 +19,7 @@ package org.springframework.boot.web.server.autoconfigure.servlet; import jakarta.servlet.DispatcherType; import org.jspecify.annotations.Nullable; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; @@ -86,15 +84,13 @@ public class ServletWebServerConfiguration { * Registers a {@link WebServerFactoryCustomizerBeanPostProcessor}. Registered via * {@link ImportBeanDefinitionRegistrar} for early registration. */ - static class BeanPostProcessorsRegistrar implements ImportBeanDefinitionRegistrar, BeanFactoryAware { + static class BeanPostProcessorsRegistrar implements ImportBeanDefinitionRegistrar { - private @Nullable ConfigurableListableBeanFactory beanFactory; + private final @Nullable ConfigurableListableBeanFactory beanFactory; - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - if (beanFactory instanceof ConfigurableListableBeanFactory listableBeanFactory) { - this.beanFactory = listableBeanFactory; - } + BeanPostProcessorsRegistrar(BeanFactory beanFactory) { + this.beanFactory = (beanFactory instanceof ConfigurableListableBeanFactory listableBeanFactory) + ? listableBeanFactory : null; } @Override