在使用spring-boot yaml配合@Value报了一下的错误:
yaml配置如下
content:
publish:
queue: xxm.community.business.content.publish.queue
exchange: xxm.community.article.publish.fanout.exchange
off:
queue: xxm.community.business.content.off.queue
exchange: xxm.community.article.off.fanout.exchange
后来debug发现

spring将off转义成了false,修改yaml为
content:
publish:
queue: xxm.community.business.content.publish.queue
exchange: xxm.community.article.publish.fanout.exchange
'off':
queue: xxm.community.business.content.off.queue
exchange: xxm.community.article.off.fanout.exchange
就可以啦

本文解决了一个关于Spring Boot中使用YAML配置文件时遇到的问题。当使用@Value注解读取YAML配置时,如果键名为off,Spring会将其误识别为布尔型false。通过在键名后面加上单引号可以避免这一问题。
491

被折叠的 条评论
为什么被折叠?



