记录 springboot 读取配置文件中文乱码问题

今天做一个短信模板读取 ,内容包含中文,由于信息敏感就不贴出来了,大概是由于设置编码问题导致读出来的内容是乱码的

  1. 先检查了文件编码格式,缺省默认继承UTF-8,没有问题。

  1. 检查springboot 读取配置文件类,之前乱码是这样的。

@Data
@Configuration
@PropertySource(value = "classpath:messagesTemplate.txt")
//@PropertySource(value = "classpath:messagesTemplate.txt", ignoreResourceNotFound = true, encoding = "UTF-8")
@ConfigurationProperties(prefix = "custer.msg")
public class CusterMessageTemplate {

	private List<String> temp = new ArrayList<String>();
}

  1. 修改正确配置文件类

@Data
@Configuration
//@PropertySource(value = "classpath:messagesTemplate.txt")
@PropertySource(value = "classpath:messagesTemplate.txt", ignoreResourceNotFound = true, encoding = "UTF-8")
@ConfigurationProperties(prefix = "custer.msg")
public class CusterMessageTemplate {

	private List<String> temp = new ArrayList<String>();
}

返回也不乱码了

posted @ 2020-12-07 11:19  DevinYang  阅读(544)  评论(0编辑  收藏  举报