我正在使用spring boot 1.4.4,我有一个测试类,如:
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@SpringBootTest(classes = {ConfigurableEnvironment.class, SecurityContextUtils.class})
@WebAppConfiguration
public class ConfigurationControllerImplTest {
private MockMvc mockMvc;
@Autowired
private ConfigurableEnvironment environment;
@Autowired
private SecurityContextUtils securityContextUtils;
@Before
public void setup() throws Exception {
mockMvc = MockMvcBuilders.standaloneSetup(new ConfigurationControllerImpl(environment, securityContextUtils)).build();
}
@Test
public void getConfigField() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/v1/conf/app/prop1")).andExpect(status().isOk());
}
}
这是我的application.yml:
---
wo:
ui.config.wo:
path: "file:/conf.json"
spring:
profiles: test
application.yml读得很好我将值存储在String路径值中,conf.json位于/ src / main / resources和/ src / test / resouces
但我这样做:MAPPER.readTree(新网址(路径));我收到错误:找不到文件。
我试过:“classpath:/config.json”,“file://config.json”只有“config.json”
有什么想法吗?
答案 0 :(得分:0)
" classpath:config.json"?
另外,我建议通过在application.yml中提供资源路径使其更加可配置,该资源路径指向资源文件夹,但稍后可以更改。