From c2b8d3de21b04110fb04167172d31bcb3cfbfa93 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 3 Oct 2022 14:36:04 +0200 Subject: [PATCH] Declare beans that can be instantiated at build-time static This commit updates the bean factory methods for beans that can be instantiated at build-time to be static. Doing so makes sure that the enclosing configuration class does not have to be resolved in order to create the instance. Closes gh-32570 --- .../reactive/ReactiveManagementContextAutoConfiguration.java | 2 +- .../web/server/ManagementContextAutoConfiguration.java | 2 +- .../web/servlet/ServletManagementContextAutoConfiguration.java | 2 +- .../data/cassandra/CassandraDataAutoConfiguration.java | 2 +- .../boot/autoconfigure/data/mongo/MongoDataConfiguration.java | 2 +- .../autoconfigure/data/r2dbc/R2dbcDataAutoConfiguration.java | 2 +- .../boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementContextAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementContextAutoConfiguration.java index 9b683bee2d..25004ecebc 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementContextAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementContextAutoConfiguration.java @@ -42,7 +42,7 @@ import org.springframework.context.annotation.Bean; public class ReactiveManagementContextAutoConfiguration { @Bean - public ManagementContextFactory reactiveWebChildContextFactory() { + public static ManagementContextFactory reactiveWebChildContextFactory() { return new ManagementContextFactory(WebApplicationType.REACTIVE, ReactiveWebServerFactory.class, ReactiveWebServerFactoryAutoConfiguration.class); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextAutoConfiguration.java index 2f8bcb2bb3..eeb6bd2d96 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextAutoConfiguration.java @@ -111,7 +111,7 @@ public class ManagementContextAutoConfiguration { static class DifferentManagementContextConfiguration { @Bean - ChildManagementContextInitializer childManagementContextInitializer( + static ChildManagementContextInitializer childManagementContextInitializer( ManagementContextFactory managementContextFactory, ApplicationContext parentContext) { return new ChildManagementContextInitializer(managementContextFactory, parentContext); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementContextAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementContextAutoConfiguration.java index 23d2ea147e..7b9fedaa4b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementContextAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementContextAutoConfiguration.java @@ -47,7 +47,7 @@ import org.springframework.context.annotation.Configuration; public class ServletManagementContextAutoConfiguration { @Bean - public ManagementContextFactory servletWebChildContextFactory() { + public static ManagementContextFactory servletWebChildContextFactory() { return new ManagementContextFactory(WebApplicationType.SERVLET, ServletWebServerFactory.class, ServletWebServerFactoryAutoConfiguration.class); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java index 2f86b6c2b6..bd70e7d00f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java @@ -69,7 +69,7 @@ public class CassandraDataAutoConfiguration { @Bean @ConditionalOnMissingBean - public CassandraManagedTypes cassandraManagedTypes(BeanFactory beanFactory) throws ClassNotFoundException { + public static CassandraManagedTypes cassandraManagedTypes(BeanFactory beanFactory) throws ClassNotFoundException { List packages = EntityScanPackages.get(beanFactory).getPackageNames(); if (packages.isEmpty() && AutoConfigurationPackages.has(beanFactory)) { packages = AutoConfigurationPackages.get(beanFactory); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.java index febecdc69b..7b5e56c116 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.java @@ -44,7 +44,7 @@ class MongoDataConfiguration { @Bean @ConditionalOnMissingBean - MongoManagedTypes mongoManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException { + static MongoManagedTypes mongoManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException { return MongoManagedTypes.fromIterable(new EntityScanner(applicationContext).scan(Document.class)); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataAutoConfiguration.java index 3f1e7720e1..69e40c1d8d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataAutoConfiguration.java @@ -72,7 +72,7 @@ public class R2dbcDataAutoConfiguration { @Bean @ConditionalOnMissingBean - RelationalManagedTypes r2dbcManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException { + static RelationalManagedTypes r2dbcManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException { return RelationalManagedTypes.fromIterable(new EntityScanner(applicationContext).scan(Table.class)); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java index 2dba20d4d7..f3db19f9a6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java @@ -190,7 +190,7 @@ public abstract class JpaBaseConfiguration { @Bean @Primary @ConditionalOnMissingBean - PersistenceManagedTypes persistenceManagedTypes(BeanFactory beanFactory, ResourceLoader resourceLoader) { + static PersistenceManagedTypes persistenceManagedTypes(BeanFactory beanFactory, ResourceLoader resourceLoader) { String[] packagesToScan = getPackagesToScan(beanFactory); return new PersistenceManagedTypesScanner(resourceLoader).scan(packagesToScan); }