Using -Dspring.config.name and -Dspring.config.location in gradle test command line

六月ゝ 毕业季﹏ 提交于 2019-12-25 07:03:05

问题


I am able to use -Dspring.config.name and -Dspring.config.location in my Spring Boot application successfully. And now want to use same -Dspring.config.location to pass to Gradle test task. It seems to be not working for me. Although I can pass other system property and use in my test classes.

I want to use this to run my tests in different environment. I know that Spring profile can be used.

any help would be appreciated

Edit: using -Dspring.config.name=app-test and/or -Dspring.config.location=classpath:/conf/app-test.properties not being picked-up up by spring to load property file. but in spring boot it is perfectly working.

mentioning of I can pass other system property and use in my test classes. meaning there is no issue in gradle to pass system property to junit test context


回答1:


-Dspring.config.location maybe wrong. If you run jar file from command line, would you try

$ java -jar myproject.jar --spring.config.location=classpath:app-test.properties

Or you can set in test class:

@TestPropertySource(locations = "classpath:app-test.properties")
public class TestClass1{...}

I hope this help!

References: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html



来源:https://stackoverflow.com/questions/27731031/using-dspring-config-name-and-dspring-config-location-in-gradle-test-command-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!