如何在 spring boot 应用程序中从 yaml 文件读取 json 作为字符串?
I need to get the json as a string / json object.
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 更改为列表,因为更多的 json(invoiceAddress)即将到来,我将不得不为每个列表。因此,如果可以将 json 原样复制到 yaml 文件中,这对我来说很容易。
最佳答案
如果您想要作为计划字符串,您应该在单引号“您的值(value)”之间添加此值。在你的 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"}'
关于java - 从 yaml Autowiring springboot 中的 json 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43384202/