今天做一个短信模板读取 ,内容包含中文,由于信息敏感就不贴出来了,大概是由于设置编码问题导致读出来的内容是乱码的
-
先检查了文件编码格式,缺省默认继承UTF-8,没有问题。
-
检查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>();
}
-
修改正确配置文件类
@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>();
}
返回也不乱码了