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:
Stephane Nicoll
2022-10-03 14:36:04 +02:00
parent d6cfcd0825
commit c2b8d3de21
7 changed files with 7 additions and 7 deletions

View File

@@ -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);

View File

@@ -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));
}

View File

@@ -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));
}

View File

@@ -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);
}