【发布时间】:2015-09-04 10:26:51
【问题描述】:
我有一个如下所示的 config.yml 文件
---
name:
archive:
documentfiles:
username: rafa
password: hello
我的配置是这样的
@ConfigurationProperties(prefix = "name")
public class YamlConfig {
private List<String> servers = new ArrayList<String>();
public List<String> getServers() {
return this.servers;
}
}
在我的测试类中,我尝试从返回的列表中获取第一个值,但它返回一个 IndexOutOfBoundsException,所以我知道 config.yml 值没有传入。有人可以提供一些帮助吗?下面是我的测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {ApplicationConfiguration.class})
public class OfflineFileViewerResourceTest {
@Test
public void password(){
fileViewer = new OfflineFileViewerResource();
YamlConfig yaml = new YamlConfig();
List<String> list = yaml.getServers();
assertEquals("archive", list.get(0));
}
}
【问题讨论】: