【发布时间】:2017-09-09 02:23:58
【问题描述】:
如何在 Spring Boot 应用程序中从 yaml 文件中读取 json 作为字符串?
我需要将 json 作为字符串/json 对象获取。
Application.yml
Shirt:
rest:
booking:
invoiceAddress: {"name":"VIA Pics AB","address1":"VIA Pics AB","address2":"Mejerivägen 3","zipCode":"11743","city":"STOCKHOLM","countryCode":"SE","email":"w.ho@Pics.fr"}
配置类
@Configuration
public class ConfigurationServiceClientConfiguration {
@Value("${Shirt.rest.booking.invoiceAddress}")
private String invoiceAddress;
@Bean
public String getInvoiceAddress(){
System.out.println(invoiceAddress);
return this.invoiceAddress;
}
}
还尝试了@JsonProperty,但不知道我的用法是否错误!
注意: 我还没有准备好将 json 更改为列表,因为会有更多 jsons(invoiceAddress)来,我将不得不为每个列表。因此,如果可以将 json 原样复制到 yaml 文件中,对我来说很容易。
【问题讨论】:
-
您还没有发布您的问题/错误!请张贴
stack trace或error log
标签: java json spring spring-boot yaml