Use constructor injection in classes that partipate in @Import

See gh-51490

Signed-off-by: piyushrajyadav <piyushyadavrajyadav@gmail.com>
This commit is contained in:
piyushrajyadav
2026-09-02 14:15:45 +01:00
committed by Andy Wilkinson
parent 352996af6a
commit e161167450
4 changed files with 18 additions and 34 deletions
@@ -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;
}
@@ -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
@@ -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
@@ -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