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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user