我正在尝试在测试包中添加test.properties
文件。
结构是
test->java-> -> test.java
-> resource -> test.properties
我的命令是
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = Publish.class)
@TestPropertySource(locations = "classpath:/src/test/java/resources/test.properties")
public class Test {
...
}
但是我总是一直得到这个
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: java.lang.IllegalStateException: Failed to add PropertySource to Environment
Caused by: java.io.FileNotFoundException: class path resource [/src/test/java/resources/test.properties] cannot be opened because it does not exist
我还有其他几种变体,但仍然出现此错误,我该如何解决呢?
其他变体:
@TestPropertySource(locations = "classpath:/test.properties")
@TestPropertySource(locations = "classpath:/resources/test.properties")
@TestPropertySource(locations = "classpath:test.properties")
问了另一个类似的问题,但我似乎无法解决我的问题stackOverflow Question