diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizerFactory.java b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizerFactory.java index 1f8e531a76d..7f9e3da7798 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizerFactory.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizerFactory.java @@ -55,6 +55,11 @@ class DynamicPropertiesContextCustomizerFactory implements ContextCustomizerFact } private void findMethods(Class testClass, Set methods) { + // Beginning with Java 16, inner classes may contain static members. + // We therefore need to search for @DynamicPropertySource methods in the + // current class after searching enclosing classes so that a local + // @DynamicPropertySource method can override properties registered in + // an enclosing class. if (TestContextAnnotationUtils.searchEnclosingClass(testClass)) { findMethods(testClass.getEnclosingClass(), methods); }