Java项目使用@Value标签读取配置文件的中文乱码问题的解决

1.在配置spring.xml文件时,声明所需的∗.properties文件时直接使用"utf−8"编码:

<context:property-placeholder location="classpath:xxx.properties" file-encoding="UTF-8"/>

2.如果在所需类上注入可使用以下方式来声明编码格式:

  @Component
  @PropertySource(value = "classpath:xxx.properties",encoding = "utf-8")
  public class test {
  @Value(
"${a}")   private String a;   }

 

posted @ 2021-02-19 10:42  雪的颜色  阅读(94)  评论(0)    收藏  举报