我在src/test
下的Main类中有我的测试代码,在scr/test/resources
下有一个测试专用属性文件
我想加载该文件,以便我可以从我的Main(测试)java类中读取它的属性,所以我做(在Main类中):
但文件没有加载,至少我假设,因为当我尝试以这种方式读取属性时:@Value("${some.property.present.in.that.file}")
private String prop;
那么prop
总是空的。
我不明白为什么这个机制在我的src/main/java
code中工作但不在测试中,ApplicationContext应该在那里,主测试类用@SpringBootTest
注释,你可以看到自己的目标,而official documentation说:
对此有何建议?
我相信如果你将测试移动到src / test / java / *,SpringBootTest将会看到它们而没有任何其他配置。