diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java index 79c688c594..108bac9fa9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java @@ -23,6 +23,7 @@ import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration.CacheConfigurationImportSelector; +import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration.CacheManagerEntityManagerFactoryDependsOnPostProcessor; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -62,7 +63,7 @@ import org.springframework.util.Assert; @EnableConfigurationProperties(CacheProperties.class) @AutoConfigureAfter({ CouchbaseAutoConfiguration.class, HazelcastAutoConfiguration.class, HibernateJpaAutoConfiguration.class, RedisAutoConfiguration.class }) -@Import(CacheConfigurationImportSelector.class) +@Import({ CacheConfigurationImportSelector.class, CacheManagerEntityManagerFactoryDependsOnPostProcessor.class }) public class CacheAutoConfiguration { @Bean @@ -77,12 +78,12 @@ public class CacheAutoConfiguration { return new CacheManagerValidator(cacheProperties, cacheManager); } - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class) @ConditionalOnBean(AbstractEntityManagerFactoryBean.class) - protected static class CacheManagerJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor { + static class CacheManagerEntityManagerFactoryDependsOnPostProcessor + extends EntityManagerFactoryDependsOnPostProcessor { - public CacheManagerJpaDependencyConfiguration() { + CacheManagerEntityManagerFactoryDependsOnPostProcessor() { super("cacheManager"); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index 0414145042..c0375d8228 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -43,6 +43,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.data.jpa.EntityManagerFactoryDependsOnPostProcessor; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayDataSourceCondition; +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayEntityManagerFactoryDependsOnPostProcessor; +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayJdbcOperationsDependsOnPostProcessor; +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayNamedParameterJdbcOperationsDependencyConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.autoconfigure.jdbc.JdbcOperationsDependsOnPostProcessor; @@ -56,6 +59,7 @@ import org.springframework.boot.jdbc.DatabaseDriver; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; import org.springframework.core.io.ResourceLoader; @@ -90,6 +94,8 @@ import org.springframework.util.StringUtils; @ConditionalOnProperty(prefix = "spring.flyway", name = "enabled", matchIfMissing = true) @AutoConfigureAfter({ DataSourceAutoConfiguration.class, JdbcTemplateAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) +@Import({ FlywayEntityManagerFactoryDependsOnPostProcessor.class, FlywayJdbcOperationsDependsOnPostProcessor.class, + FlywayNamedParameterJdbcOperationsDependencyConfiguration.class }) public class FlywayAutoConfiguration { @Bean @@ -106,6 +112,9 @@ public class FlywayAutoConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnMissingBean(Flyway.class) @EnableConfigurationProperties({ DataSourceProperties.class, FlywayProperties.class }) + @Import({ FlywayMigrationInitializerEntityManagerFactoryDependsOnPostProcessor.class, + FlywayMigrationInitializerJdbcOperationsDependsOnPostProcessor.class, + FlywayMigrationInitializerNamedParameterJdbcOperationsDependsOnPostProcessor.class }) public static class FlywayConfiguration { @Bean @@ -257,91 +266,85 @@ public class FlywayAutoConfiguration { return new FlywayMigrationInitializer(flyway, migrationStrategy.getIfAvailable()); } - /** - * Additional configuration to ensure that {@link EntityManagerFactory} beans - * depend on any {@link FlywayMigrationInitializer} beans. - */ - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class) - @ConditionalOnBean(AbstractEntityManagerFactoryBean.class) - protected static class FlywayInitializerJpaDependencyConfiguration - extends EntityManagerFactoryDependsOnPostProcessor { - - public FlywayInitializerJpaDependencyConfiguration() { - super(FlywayMigrationInitializer.class); - } + } + + /** + * Post processor to ensure that {@link EntityManagerFactory} beans depend on any + * {@link FlywayMigrationInitializer} beans. + */ + @ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class) + @ConditionalOnBean(AbstractEntityManagerFactoryBean.class) + static class FlywayMigrationInitializerEntityManagerFactoryDependsOnPostProcessor + extends EntityManagerFactoryDependsOnPostProcessor { + FlywayMigrationInitializerEntityManagerFactoryDependsOnPostProcessor() { + super(FlywayMigrationInitializer.class); } - /** - * Additional configuration to ensure that {@link JdbcOperations} beans depend on - * any {@link FlywayMigrationInitializer} beans. - */ - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(JdbcOperations.class) - @ConditionalOnBean(JdbcOperations.class) - protected static class FlywayInitializerJdbcOperationsDependencyConfiguration - extends JdbcOperationsDependsOnPostProcessor { - - public FlywayInitializerJdbcOperationsDependencyConfiguration() { - super(FlywayMigrationInitializer.class); - } + } + + /** + * Post processor to ensure that {@link JdbcOperations} beans depend on any + * {@link FlywayMigrationInitializer} beans. + */ + @ConditionalOnClass(JdbcOperations.class) + @ConditionalOnBean(JdbcOperations.class) + static class FlywayMigrationInitializerJdbcOperationsDependsOnPostProcessor + extends JdbcOperationsDependsOnPostProcessor { + FlywayMigrationInitializerJdbcOperationsDependsOnPostProcessor() { + super(FlywayMigrationInitializer.class); } - /** - * Additional configuration to ensure that {@link NamedParameterJdbcOperations} - * beans depend on any {@link FlywayMigrationInitializer} beans. - */ - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(NamedParameterJdbcOperations.class) - @ConditionalOnBean(NamedParameterJdbcOperations.class) - protected static class FlywayInitializerNamedParameterJdbcOperationsDependencyConfiguration - extends NamedParameterJdbcOperationsDependsOnPostProcessor { - - public FlywayInitializerNamedParameterJdbcOperationsDependencyConfiguration() { - super(FlywayMigrationInitializer.class); - } + } + /** + * Post processor to ensure that {@link NamedParameterJdbcOperations} beans depend on + * any {@link FlywayMigrationInitializer} beans. + */ + @ConditionalOnClass(NamedParameterJdbcOperations.class) + @ConditionalOnBean(NamedParameterJdbcOperations.class) + static class FlywayMigrationInitializerNamedParameterJdbcOperationsDependsOnPostProcessor + extends NamedParameterJdbcOperationsDependsOnPostProcessor { + + FlywayMigrationInitializerNamedParameterJdbcOperationsDependsOnPostProcessor() { + super(FlywayMigrationInitializer.class); } } /** - * Additional configuration to ensure that {@link EntityManagerFactory} beans depend - * on any {@link Flyway} beans. + * Post processor to ensure that {@link EntityManagerFactory} beans depend on any + * {@link Flyway} beans. */ - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class) @ConditionalOnBean(AbstractEntityManagerFactoryBean.class) - protected static class FlywayJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor { + static class FlywayEntityManagerFactoryDependsOnPostProcessor extends EntityManagerFactoryDependsOnPostProcessor { - public FlywayJpaDependencyConfiguration() { + FlywayEntityManagerFactoryDependsOnPostProcessor() { super(Flyway.class); } } /** - * Additional configuration to ensure that {@link JdbcOperations} beans depend on any + * Post processor to ensure that {@link JdbcOperations} beans depend on any * {@link Flyway} beans. */ - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(JdbcOperations.class) @ConditionalOnBean(JdbcOperations.class) - protected static class FlywayJdbcOperationsDependencyConfiguration extends JdbcOperationsDependsOnPostProcessor { + static class FlywayJdbcOperationsDependsOnPostProcessor extends JdbcOperationsDependsOnPostProcessor { - public FlywayJdbcOperationsDependencyConfiguration() { + FlywayJdbcOperationsDependsOnPostProcessor() { super(Flyway.class); } } /** - * Additional configuration to ensure that {@link NamedParameterJdbcOperations} beans - * depend on any {@link Flyway} beans. + * Post processor to ensure that {@link NamedParameterJdbcOperations} beans depend on + * any {@link Flyway} beans. */ - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(NamedParameterJdbcOperations.class) @ConditionalOnBean(NamedParameterJdbcOperations.class) protected static class FlywayNamedParameterJdbcOperationsDependencyConfiguration diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfiguration.java index e7d06ad26e..38f84112a0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfiguration.java @@ -25,10 +25,11 @@ import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.data.jpa.EntityManagerFactoryDependsOnPostProcessor; +import org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration.HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @@ -42,18 +43,14 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @Configuration(proxyBeanMethods = false) @ConditionalOnClass({ HazelcastInstance.class, LocalContainerEntityManagerFactoryBean.class }) @AutoConfigureAfter({ HazelcastAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) +@Import(HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor.class) public class HazelcastJpaDependencyAutoConfiguration { - @Bean @Conditional(OnHazelcastAndJpaCondition.class) - public static HazelcastInstanceJpaDependencyPostProcessor hazelcastInstanceJpaDependencyPostProcessor() { - return new HazelcastInstanceJpaDependencyPostProcessor(); - } - - private static class HazelcastInstanceJpaDependencyPostProcessor + static class HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor extends EntityManagerFactoryDependsOnPostProcessor { - HazelcastInstanceJpaDependencyPostProcessor() { + HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor() { super("hazelcastInstance"); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java index ba5de5581b..9e9b766ecb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java @@ -38,6 +38,8 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.autoconfigure.jdbc.JdbcOperationsDependsOnPostProcessor; import org.springframework.boot.autoconfigure.jdbc.NamedParameterJdbcOperationsDependsOnPostProcessor; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseDataSourceCondition; +import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseJdbcOperationsDependsOnPostProcessor; +import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; @@ -68,6 +70,8 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @ConditionalOnProperty(prefix = "spring.liquibase", name = "enabled", matchIfMissing = true) @Conditional(LiquibaseDataSourceCondition.class) @AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) +@Import({ LiquibaseJdbcOperationsDependsOnPostProcessor.class, + LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor.class }) public class LiquibaseAutoConfiguration { @Bean @@ -79,7 +83,7 @@ public class LiquibaseAutoConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnMissingBean(SpringLiquibase.class) @EnableConfigurationProperties({ DataSourceProperties.class, LiquibaseProperties.class }) - @Import(LiquibaseJpaDependencyConfiguration.class) + @Import(LiquibaseEntityManagerFactoryDependsOnPostProcessor.class) public static class LiquibaseConfiguration { private final LiquibaseProperties properties; @@ -148,15 +152,15 @@ public class LiquibaseAutoConfiguration { } /** - * Additional configuration to ensure that {@link EntityManagerFactory} beans depend - * on the liquibase bean. + * Post processor to ensure that {@link EntityManagerFactory} beans depend on the + * liquibase bean. */ - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class) @ConditionalOnBean(AbstractEntityManagerFactoryBean.class) - protected static class LiquibaseJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor { + static class LiquibaseEntityManagerFactoryDependsOnPostProcessor + extends EntityManagerFactoryDependsOnPostProcessor { - public LiquibaseJpaDependencyConfiguration() { + LiquibaseEntityManagerFactoryDependsOnPostProcessor() { super(SpringLiquibase.class); } @@ -166,28 +170,26 @@ public class LiquibaseAutoConfiguration { * Additional configuration to ensure that {@link JdbcOperations} beans depend on the * liquibase bean. */ - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(JdbcOperations.class) @ConditionalOnBean(JdbcOperations.class) - protected static class LiquibaseJdbcOperationsDependencyConfiguration extends JdbcOperationsDependsOnPostProcessor { + static class LiquibaseJdbcOperationsDependsOnPostProcessor extends JdbcOperationsDependsOnPostProcessor { - public LiquibaseJdbcOperationsDependencyConfiguration() { + LiquibaseJdbcOperationsDependsOnPostProcessor() { super(SpringLiquibase.class); } } /** - * Additional configuration to ensure that {@link NamedParameterJdbcOperations} beans - * depend on the liquibase bean. + * Post processor to ensure that {@link NamedParameterJdbcOperations} beans depend on + * the liquibase bean. */ - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(NamedParameterJdbcOperations.class) @ConditionalOnBean(NamedParameterJdbcOperations.class) - protected static class LiquibaseNamedParameterJdbcOperationsDependencyConfiguration + static class LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor extends NamedParameterJdbcOperationsDependsOnPostProcessor { - public LiquibaseNamedParameterJdbcOperationsDependencyConfiguration() { + LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor() { super(SpringLiquibase.class); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java index b7abafe1a9..b0fb3f57f2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java @@ -59,11 +59,14 @@ import org.springframework.boot.autoconfigure.data.mongo.MongoClientDependsOnBea import org.springframework.boot.autoconfigure.data.mongo.ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoProperties; +import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration.EmbeddedMongoClientDependsOnBeanFactoryPostProcessor; +import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration.EmbeddedReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; @@ -84,6 +87,8 @@ import org.springframework.data.mongodb.core.ReactiveMongoClientFactoryBean; @EnableConfigurationProperties({ MongoProperties.class, EmbeddedMongoProperties.class }) @AutoConfigureBefore(MongoAutoConfiguration.class) @ConditionalOnClass({ MongoClient.class, MongodStarter.class }) +@Import({ EmbeddedMongoClientDependsOnBeanFactoryPostProcessor.class, + EmbeddedReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor.class }) public class EmbeddedMongoAutoConfiguration { private static final byte[] IP4_LOOPBACK_ADDRESS = { 127, 0, 0, 1 }; @@ -212,30 +217,29 @@ public class EmbeddedMongoAutoConfiguration { } /** - * Additional configuration to ensure that {@link MongoClient} beans depend on any + * Post processor to ensure that {@link MongoClient} beans depend on any * {@link MongodExecutable} beans. */ - @Configuration(proxyBeanMethods = false) @ConditionalOnClass({ MongoClient.class, MongoClientFactoryBean.class }) - protected static class EmbeddedMongoDependencyConfiguration extends MongoClientDependsOnBeanFactoryPostProcessor { + static class EmbeddedMongoClientDependsOnBeanFactoryPostProcessor + extends MongoClientDependsOnBeanFactoryPostProcessor { - EmbeddedMongoDependencyConfiguration() { + EmbeddedMongoClientDependsOnBeanFactoryPostProcessor() { super(MongodExecutable.class); } } /** - * Additional configuration to ensure that + * Post processor to ensure that * {@link com.mongodb.reactivestreams.client.MongoClient} beans depend on any * {@link MongodExecutable} beans. */ - @Configuration(proxyBeanMethods = false) @ConditionalOnClass({ com.mongodb.reactivestreams.client.MongoClient.class, ReactiveMongoClientFactoryBean.class }) - protected static class EmbeddedReactiveMongoDependencyConfiguration + static class EmbeddedReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor extends ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor { - EmbeddedReactiveMongoDependencyConfiguration() { + EmbeddedReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor() { super(MongodExecutable.class); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfigurationTests.java index d3c75935a7..6fa67cad4a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfigurationTests.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.data.jpa.EntityManagerFactoryDependsOnPostProcessor; +import org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration.HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; @@ -44,6 +45,9 @@ import static org.mockito.Mockito.mock; */ class HazelcastJpaDependencyAutoConfigurationTests { + private static final String POST_PROCESSOR_BEAN_NAME = HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor.class + .getName(); + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, HazelcastJpaDependencyAutoConfiguration.class)) @@ -53,7 +57,7 @@ class HazelcastJpaDependencyAutoConfigurationTests { @Test void registrationIfHazelcastInstanceHasRegularBeanName() { this.contextRunner.withUserConfiguration(HazelcastConfiguration.class).run((context) -> { - assertThat(postProcessors(context)).containsKey("hazelcastInstanceJpaDependencyPostProcessor"); + assertThat(postProcessors(context)).containsKey(POST_PROCESSOR_BEAN_NAME); assertThat(entityManagerFactoryDependencies(context)).contains("hazelcastInstance"); }); } @@ -62,7 +66,7 @@ class HazelcastJpaDependencyAutoConfigurationTests { void noRegistrationIfHazelcastInstanceHasCustomBeanName() { this.contextRunner.withUserConfiguration(HazelcastCustomNameConfiguration.class).run((context) -> { assertThat(entityManagerFactoryDependencies(context)).doesNotContain("hazelcastInstance"); - assertThat(postProcessors(context)).doesNotContainKey("hazelcastInstanceJpaDependencyPostProcessor"); + assertThat(postProcessors(context)).doesNotContainKey(POST_PROCESSOR_BEAN_NAME); }); } @@ -70,7 +74,7 @@ class HazelcastJpaDependencyAutoConfigurationTests { void noRegistrationWithNoHazelcastInstance() { this.contextRunner.run((context) -> { assertThat(entityManagerFactoryDependencies(context)).doesNotContain("hazelcastInstance"); - assertThat(postProcessors(context)).doesNotContainKey("hazelcastInstanceJpaDependencyPostProcessor"); + assertThat(postProcessors(context)).doesNotContainKey(POST_PROCESSOR_BEAN_NAME); }); } @@ -78,8 +82,7 @@ class HazelcastJpaDependencyAutoConfigurationTests { void noRegistrationWithNoEntityManagerFactory() { new ApplicationContextRunner().withUserConfiguration(HazelcastConfiguration.class) .withConfiguration(AutoConfigurations.of(HazelcastJpaDependencyAutoConfiguration.class)) - .run((context) -> assertThat(postProcessors(context)) - .doesNotContainKey("hazelcastInstanceJpaDependencyPostProcessor")); + .run((context) -> assertThat(postProcessors(context)).doesNotContainKey(POST_PROCESSOR_BEAN_NAME)); } private Map postProcessors( diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java index 266b281eef..23fd60c49c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java @@ -112,8 +112,7 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes @Test void testDataScript() { // This can't succeed because the data SQL is executed immediately after the - // schema - // and Hibernate hasn't initialized yet at that point + // schema and Hibernate hasn't initialized yet at that point contextRunner().withPropertyValues("spring.datasource.data:classpath:/city.sql").run((context) -> { assertThat(context).hasFailed(); assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class); diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java index 17359e6cdd..6bbffe04ee 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java @@ -41,12 +41,14 @@ import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.data.jpa.EntityManagerFactoryDependsOnPostProcessor; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration.DatabaseShutdownExecutorEntityManagerFactoryDependsOnPostProcessor; import org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration.DevToolsDataSourceCondition; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ConfigurationCondition; +import org.springframework.context.annotation.Import; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @@ -61,6 +63,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @AutoConfigureAfter(DataSourceAutoConfiguration.class) @Conditional({ OnEnabledDevToolsCondition.class, DevToolsDataSourceCondition.class }) @Configuration(proxyBeanMethods = false) +@Import(DatabaseShutdownExecutorEntityManagerFactoryDependsOnPostProcessor.class) public class DevToolsDataSourceAutoConfiguration { @Bean @@ -70,16 +73,15 @@ public class DevToolsDataSourceAutoConfiguration { } /** - * Additional configuration to ensure that - * {@link javax.persistence.EntityManagerFactory} beans depend on the - * {@code inMemoryDatabaseShutdownExecutor} bean. + * Post processor to ensure that {@link javax.persistence.EntityManagerFactory} beans + * depend on the {@code inMemoryDatabaseShutdownExecutor} bean. */ - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class) @ConditionalOnBean(AbstractEntityManagerFactoryBean.class) - static class DatabaseShutdownExecutorJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor { + static class DatabaseShutdownExecutorEntityManagerFactoryDependsOnPostProcessor + extends EntityManagerFactoryDependsOnPostProcessor { - DatabaseShutdownExecutorJpaDependencyConfiguration() { + DatabaseShutdownExecutorEntityManagerFactoryDependsOnPostProcessor() { super("inMemoryDatabaseShutdownExecutor"); } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/elasticsearch/HibernateSearchElasticsearchExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/elasticsearch/HibernateSearchElasticsearchExample.java index f216a1d9e5..02a6922756 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/elasticsearch/HibernateSearchElasticsearchExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/elasticsearch/HibernateSearchElasticsearchExample.java @@ -19,7 +19,7 @@ package org.springframework.boot.docs.elasticsearch; import javax.persistence.EntityManagerFactory; import org.springframework.boot.autoconfigure.data.jpa.EntityManagerFactoryDependsOnPostProcessor; -import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; /** * Example configuration for configuring Hibernate to depend on Elasticsearch so that @@ -34,10 +34,11 @@ public class HibernateSearchElasticsearchExample { * {@link EntityManagerFactoryDependsOnPostProcessor} that ensures that * {@link EntityManagerFactory} beans depend on the {@code elasticsearchClient} bean. */ - @Configuration(proxyBeanMethods = false) - static class ElasticsearchJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor { + @Component + static class ElasticsearchEntityManagerFactoryDependsOnPostProcessor + extends EntityManagerFactoryDependsOnPostProcessor { - ElasticsearchJpaDependencyConfiguration() { + ElasticsearchEntityManagerFactoryDependsOnPostProcessor() { super("elasticsearchClient"); }