【发布时间】:2019-06-04 11:08:57
【问题描述】:
我正在使用 Spring Boot 应用程序。我想进行一些单元测试并在 src/test/resources 中使用属性文件。
带有@Value 注释的属性没有被属性值填充。
我尝试将<testResources> 添加到 pom 中,但它不起作用。
我尝试在@PropertySource 中的classpath 关键字之后添加*,但它也不起作用。
@Configuration
@PropertySource("classpath:application-test.properties")
public class UnitTestConfiguration {
}
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {UnitTestConfiguration.class})
class AccountsControllerTest {
@Value("${web-client-factory.valid-jwt}")
public String validJwt; // null in debug
}
如果 spring 没有找到属性但它什么都不做并且我的属性是 null,我预计会出现异常。
【问题讨论】:
标签: spring maven spring-boot junit