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
This commit is contained in:
parent
d6cfcd0825
commit
c2b8d3de21
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<String> packages = EntityScanPackages.get(beanFactory).getPackageNames();
|
||||
if (packages.isEmpty() && AutoConfigurationPackages.has(beanFactory)) {
|
||||
packages = AutoConfigurationPackages.get(beanFactory);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue