@Value读取配置文件,中文字符乱码

如题。

解决方案:

在applicationContext.xml中加入

    <context:property-placeholder ignore-resource-not-found="true" location="classpath:inspectionConf/inspectionConf.properties" file-encoding="utf-8"/>


在要使用@Value的类名上方声明

@PropertySource(value = "classpath:a.properties")
@Getter


使用时:

@Value("${worker}")
 private String workers;


不再乱码。


另附五种读取配置文件的方式:http://www.cnblogs.com/hafiz/p/5876243.html


版权声明:本文为danchaofan0534原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。