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

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

spring 中文乱码 @Value *.properties


在spring中我们常常使用.properties对一些属性进行一个提前配置, spring 在读取*.properties文件时,默认使用的是asci码, 这时 我们需要对其编码进行转换. 当然 方法有很多种 ,我说以下几种


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

<context:property-placeholder location="classpath:conf/*.properties" file-encoding="UTF-8"/>
  • 1

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

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

3.,unicode不设置编码格式,编写文件时将中文转化为unicode编码
4. IntelliJIDEA!!!idea,!
idea 会自动帮我们进行如上的第三步的

 

--------------------- 本文来自 J3oker 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/J3oker/article/details/53839210?utm_source=copy 

猜你喜欢

转载自www.cnblogs.com/coder-wzr/p/9719315.html