使用junit-platform-console-standalone执行@SpringBootTest时无法读取application.properties的问题求助
junit-platform-console-standalone执行@SpringBootTest时无法读取application.properties的问题求助
各位好,我最近碰到一个棘手的问题,想请大家帮忙看看:
我把整个Spring Boot应用打包成了包含所有依赖的fat jar,在IntelliJ IDEA里直接通过方法或类的测试运行器启动@SpringBootTest测试时,一切都正常,程序能正确读取src/main/resources/config目录下的application.properties配置文件。
但当我用junit-platform-console-standalone jar来运行测试时,程序完全读不到这个配置文件里的任何属性。我用的启动命令是:
java "-Dfile.encoding=UTF-8" "-Dallure.results.directory=config/reports/allure" -jar junit-platform-console-standalone-1.11.4.jar --class-path "target/classes;target/test-classes;target/rest-assured-5.5.0-jar-with-dependencies.jar" --select-package com.myapp --reports-dir=config/reports --details=tree --details-theme=unicode
我已经尝试过以下几种方法,但都没有解决问题:
- 调整
application.properties的存放位置:先后移到src/main/resources、src/test/resources/config、src/test/resources目录下测试 - 在启动命令中添加配置参数:
-Dspring.profile.location=file:./config/application.properties-Dspring.profile.location=classpath:/config/application.properties
- 在测试类上添加注解指定配置文件:
@TestPropertySource(properties = "spring.config.additional-location=classpath:config/application.properties")@TestPropertySource(locations = "classpath:config/application.properties")
有没有大佬知道问题到底出在哪?或者还有什么其他排查方向可以尝试吗?
内容来源于stack exchange
相关产品推荐
相关产品推荐

