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 {
|
public class ReactiveManagementContextAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ManagementContextFactory reactiveWebChildContextFactory() {
|
public static ManagementContextFactory reactiveWebChildContextFactory() {
|
||||||
return new ManagementContextFactory(WebApplicationType.REACTIVE, ReactiveWebServerFactory.class,
|
return new ManagementContextFactory(WebApplicationType.REACTIVE, ReactiveWebServerFactory.class,
|
||||||
ReactiveWebServerFactoryAutoConfiguration.class);
|
ReactiveWebServerFactoryAutoConfiguration.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class ManagementContextAutoConfiguration {
|
||||||
static class DifferentManagementContextConfiguration {
|
static class DifferentManagementContextConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
ChildManagementContextInitializer childManagementContextInitializer(
|
static ChildManagementContextInitializer childManagementContextInitializer(
|
||||||
ManagementContextFactory managementContextFactory, ApplicationContext parentContext) {
|
ManagementContextFactory managementContextFactory, ApplicationContext parentContext) {
|
||||||
return new ChildManagementContextInitializer(managementContextFactory, parentContext);
|
return new ChildManagementContextInitializer(managementContextFactory, parentContext);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
public class ServletManagementContextAutoConfiguration {
|
public class ServletManagementContextAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ManagementContextFactory servletWebChildContextFactory() {
|
public static ManagementContextFactory servletWebChildContextFactory() {
|
||||||
return new ManagementContextFactory(WebApplicationType.SERVLET, ServletWebServerFactory.class,
|
return new ManagementContextFactory(WebApplicationType.SERVLET, ServletWebServerFactory.class,
|
||||||
ServletWebServerFactoryAutoConfiguration.class);
|
ServletWebServerFactoryAutoConfiguration.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class CassandraDataAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public CassandraManagedTypes cassandraManagedTypes(BeanFactory beanFactory) throws ClassNotFoundException {
|
public static CassandraManagedTypes cassandraManagedTypes(BeanFactory beanFactory) throws ClassNotFoundException {
|
||||||
List<String> packages = EntityScanPackages.get(beanFactory).getPackageNames();
|
List<String> packages = EntityScanPackages.get(beanFactory).getPackageNames();
|
||||||
if (packages.isEmpty() && AutoConfigurationPackages.has(beanFactory)) {
|
if (packages.isEmpty() && AutoConfigurationPackages.has(beanFactory)) {
|
||||||
packages = AutoConfigurationPackages.get(beanFactory);
|
packages = AutoConfigurationPackages.get(beanFactory);
|
||||||
|
|
|
@ -44,7 +44,7 @@ class MongoDataConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
MongoManagedTypes mongoManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException {
|
static MongoManagedTypes mongoManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException {
|
||||||
return MongoManagedTypes.fromIterable(new EntityScanner(applicationContext).scan(Document.class));
|
return MongoManagedTypes.fromIterable(new EntityScanner(applicationContext).scan(Document.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class R2dbcDataAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
RelationalManagedTypes r2dbcManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException {
|
static RelationalManagedTypes r2dbcManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException {
|
||||||
return RelationalManagedTypes.fromIterable(new EntityScanner(applicationContext).scan(Table.class));
|
return RelationalManagedTypes.fromIterable(new EntityScanner(applicationContext).scan(Table.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ public abstract class JpaBaseConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
@Primary
|
@Primary
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
PersistenceManagedTypes persistenceManagedTypes(BeanFactory beanFactory, ResourceLoader resourceLoader) {
|
static PersistenceManagedTypes persistenceManagedTypes(BeanFactory beanFactory, ResourceLoader resourceLoader) {
|
||||||
String[] packagesToScan = getPackagesToScan(beanFactory);
|
String[] packagesToScan = getPackagesToScan(beanFactory);
|
||||||
return new PersistenceManagedTypesScanner(resourceLoader).scan(packagesToScan);
|
return new PersistenceManagedTypesScanner(resourceLoader).scan(packagesToScan);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue