From 812c965a5c6feb802315449d7a06912560021dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Van=C4=9Bk?= Date: Mon, 25 Nov 2024 18:05:02 +0100 Subject: [PATCH] #276 add Ordered interface to internal bean post processors to ensure correct processing order --- .../io/zonky/test/db/flyway/FlywayDatabaseExtension.java | 8 +++++++- .../test/db/flyway/FlywayPropertiesPostProcessor.java | 8 +++++++- .../test/db/liquibase/LiquibaseDatabaseExtension.java | 8 +++++++- .../db/liquibase/LiquibasePropertiesPostProcessor.java | 8 +++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/FlywayDatabaseExtension.java b/embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/FlywayDatabaseExtension.java index 0b5fe97..aa6fb16 100644 --- a/embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/FlywayDatabaseExtension.java +++ b/embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/FlywayDatabaseExtension.java @@ -40,6 +40,7 @@ import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.support.NameMatchMethodPointcutAdvisor; import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.core.Ordered; import java.util.Arrays; import java.util.Collection; @@ -59,7 +60,7 @@ import static com.google.common.base.Preconditions.checkState; -public class FlywayDatabaseExtension implements BeanPostProcessor { +public class FlywayDatabaseExtension implements BeanPostProcessor, Ordered { private static final FlywayVersion flywayVersion = FlywayClassUtils.getFlywayVersion(); @@ -68,6 +69,11 @@ public class FlywayDatabaseExtension implements BeanPostProcessor { protected final Multimap flywayBeans = HashMultimap.create(); protected final BlockingQueue pendingOperations = new LinkedBlockingQueue<>(); + @Override + public int getOrder() { + return Ordered.HIGHEST_PRECEDENCE + 1; + } + @Override public Object postProcessBeforeInitialization(Object bean, String beanName) { if (bean instanceof AopInfrastructureBean) { diff --git a/embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/FlywayPropertiesPostProcessor.java b/embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/FlywayPropertiesPostProcessor.java index 439fd05..fb9eef0 100644 --- a/embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/FlywayPropertiesPostProcessor.java +++ b/embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/FlywayPropertiesPostProcessor.java @@ -3,8 +3,14 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.flyway.FlywayProperties; +import org.springframework.core.Ordered; -public class FlywayPropertiesPostProcessor implements BeanPostProcessor { +public class FlywayPropertiesPostProcessor implements BeanPostProcessor, Ordered { + + @Override + public int getOrder() { + return Ordered.LOWEST_PRECEDENCE - 1; + } @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { diff --git a/embedded-database-spring-test/src/main/java/io/zonky/test/db/liquibase/LiquibaseDatabaseExtension.java b/embedded-database-spring-test/src/main/java/io/zonky/test/db/liquibase/LiquibaseDatabaseExtension.java index 9593f14..996e05c 100644 --- a/embedded-database-spring-test/src/main/java/io/zonky/test/db/liquibase/LiquibaseDatabaseExtension.java +++ b/embedded-database-spring-test/src/main/java/io/zonky/test/db/liquibase/LiquibaseDatabaseExtension.java @@ -28,10 +28,16 @@ import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.support.NameMatchMethodPointcutAdvisor; import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.core.Ordered; import static com.google.common.base.Preconditions.checkState; -public class LiquibaseDatabaseExtension implements BeanPostProcessor { +public class LiquibaseDatabaseExtension implements BeanPostProcessor, Ordered { + + @Override + public int getOrder() { + return Ordered.HIGHEST_PRECEDENCE + 1; + } @Override public Object postProcessBeforeInitialization(Object bean, String beanName) { diff --git a/embedded-database-spring-test/src/main/java/io/zonky/test/db/liquibase/LiquibasePropertiesPostProcessor.java b/embedded-database-spring-test/src/main/java/io/zonky/test/db/liquibase/LiquibasePropertiesPostProcessor.java index afe48d9..01ea3cf 100644 --- a/embedded-database-spring-test/src/main/java/io/zonky/test/db/liquibase/LiquibasePropertiesPostProcessor.java +++ b/embedded-database-spring-test/src/main/java/io/zonky/test/db/liquibase/LiquibasePropertiesPostProcessor.java @@ -19,8 +19,14 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties; +import org.springframework.core.Ordered; -public class LiquibasePropertiesPostProcessor implements BeanPostProcessor { +public class LiquibasePropertiesPostProcessor implements BeanPostProcessor, Ordered { + + @Override + public int getOrder() { + return Ordered.LOWEST_PRECEDENCE - 1; + } @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {