spring使用@Value标签读取.properties文件的中文乱码问题的解决

时间:2017-04-01 23:11:44   收藏:0   阅读:2540

 最近测试某个老系统的时候,启动的时候发@Value注入的中文是乱码,文件使用GBK/UTF-8的时候均会出现乱码问题,但是spring配置文件里面注入的占位符并没有这个问题,bean文件设置了file-encoding="UTF-8"亦如此。

经查,可通过如下方式解决:

@Component
@PropertySource(value = "classpath:conf/spider.properties",encoding = "utf-8")
@Getter
public class SpiderConfig {
    @Value("${a}")
    private String a;
    @Value("${b}")
    private String b;
}

亦或是

,unicode

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!