diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java index ecd72daa00..15cef33505 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java @@ -248,12 +248,21 @@ public class TestContextAotGenerator { // @ContextConfiguration(locations = ...) registerHintsForClasspathResources(mergedConfig.getLocations()); + + // @TestPropertySource(locations = ... ) + registerHintsForClasspathResources(mergedConfig.getPropertySourceLocations()); } private void registerHintsForClasspathResources(String... locations) { Arrays.stream(locations) .filter(location -> location.startsWith(CLASSPATH_URL_PREFIX)) - .map(location -> location.substring(CLASSPATH_URL_PREFIX.length())) + .map(location -> { + location = location.substring(CLASSPATH_URL_PREFIX.length()); + if (!location.startsWith("/")) { + location = "/" + location; + } + return location; + }) .forEach(this.runtimeHints.resources()::registerPattern); } diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java index 9ecac208e5..7952d33b4a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java @@ -171,6 +171,10 @@ class TestContextAotGeneratorTests extends AbstractAotTests { // @ContextConfiguration(locations=...) assertThat(resource().forResource("/org/springframework/test/context/aot/samples/xml/test-config.xml")) .accepts(runtimeHints); + + // @TestPropertySource(locations = ... ) + assertThat(resource().forResource("/org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.properties")) + .accepts(runtimeHints); } private static void assertReflectionRegistered(RuntimeHints runtimeHints, String type, MemberCategory memberCategory) { diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.java index 2a1ffde57b..13f298c620 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.java @@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) // Override the default loader configured by the CustomXmlBootstrapper @ContextConfiguration(classes = BasicTestConfiguration.class, loader = AnnotationConfigContextLoader.class) -@TestPropertySource(properties = "test.engine = vintage") +@TestPropertySource public class BasicSpringVintageTests { @Autowired diff --git a/spring-test/src/test/resources/org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.properties b/spring-test/src/test/resources/org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.properties new file mode 100644 index 0000000000..2156ea765a --- /dev/null +++ b/spring-test/src/test/resources/org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.properties @@ -0,0 +1 @@ +test.engine = vintage \ No newline at end of file