问题
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