【发布时间】:2023-04-02 12:44:01
【问题描述】:
在我的配置类中我有
@Value("${some.vars}")
private List<String> vars;
现在在我的测试中,我希望能够设置 this 的值,所以我有这个
@SpringBootTest
public class MyTest {
@Test
public void test() {
ApplicationContextRunner runner = new ApplicationContextRunner();
runner
.withConfiguration(AutoConfigurations.of(MyConfiguration.class))
.withUserConfiguration(UserConfiguration.class)
.withPropertyValues("some.vars=A,B,C")
.run(ctx -> {
// some test assertions
});
}
我将A,B,C 作为一个字符串绑定到List<String> 的第0 个位置。我希望它在vars 中呈现并绑定为 List
【问题讨论】:
标签: java spring spring-boot junit4