找了很久都没有一个可以用的读取properties文件然后转换成Map的源码, 这里提供一个思路, 利用Properties类的load方法来加载自定义的properties
@Bean
public Propertiesi18nMessage() {
Properties p =new Properties();
try{
final ClassPathResource classPathResource =new ClassPathResource("i18n/messages.properties");
p.load(new InputStreamReader(classPathResource.getInputStream(), "UTF-8"));
}catch (Exception e){
e.printStackTrace();
}
return p;
}
Properties 转 map就非常简单了,
Map<String, String> map = new HashMap<String, String>((Map) p);
就行