【发布时间】:2018-06-20 17:12:12
【问题描述】:
我正在使用 Spring Boot 1.5.8
我的application.yml 有以下属性:
my:
path: \\\\hostname\\dir
根据我对YAML spec 5.7. Escaped Characters 的了解,双反斜杠\\ 是单反斜杠的有效转义序列,因此上述配置应产生my.path: \\hostname\dir 的值。
但是,在我的应用程序中,我可以看到该属性的值包含双反斜杠:
@RunWith(SpringRunner.class)
@SpringBootTest
public class PropTest {
@Getter
@Setter
public static class MyProp {
private String path;
}
@Autowired
private MyProp my;
@Test
public void testProp() {
System.out.println(my.path);
}
@Configuration
@EnableConfigurationProperties
public static class Config {
@Bean
@ConfigurationProperties("my")
public MyProp my() {
return new MyProp();
}
}
}
打印:
\\\\host\\dir
我不能将 application.yml 中的值放在引号中,因为该文件是由配置系统 (SaltStack) 生成的,并且它有自己的 Yaml 渲染库。
这是 Spring Boot 中的错误/Spring Boot 使用的 Yaml 库吗?有没有办法强制 Spring Boot 将 Yaml 中的双反斜杠视为单个反斜杠的转义?
【问题讨论】:
标签: java spring spring-boot yaml