[英]I don't know how to replace config.properties by test properties Spring / JUnit
问题是,有一个使用配置类来获取所有配置属性的项目
@Configuration
@PropertySource("file:/external/path/config/config.properties")
public class AppSettings {
@Value("${SOME.PROPERTY}")
public String SOME_PROPERTY;
}
因此,在我的测试配置类中,我只是使用以下内容替换属性:
@TestPropertySource("classpath:testconfig.properties")
这样就可以了(在我的本地环境中),它用testconfig替换了配置。 但是,当我在认证环境中部署它时,它会抛出FileNotFoundException: /external/path/config/config.properties
此config.properties在外部路径中,因此部署无法访问该路径。
该testconfig.properties在项目内部,所以我需要读取它而不是config.properties ...,但仍在读取它并抛出错误。
运行测试时如何正确替换config.properties?
尝试在以下位置添加点:
@PropertySource("file:./server/path/config/config.properties")
另请参阅spring文档的这一章,这可能对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.