学习springboot时读取配置文件自定义内容出现中文乱码总结。
方法一:
Windowd→Preferences→General→Editors→Text Editors→Spelling里面的Encoding为UTF-8
方法二:
Windowd→Preferences→General→Content Types里面的Text→Java Properties File最下面的Default encoding为UTF–8
方法三:
下载PerportiesEditor插件Windowd→Preferences→General→Editors→Flie Associations里面设置*.properties文件使用Perporties File Editor为默认打开
方法四:
主配置文件application.properties点击右键→Properties→Resource设置Text file encoding为UTF-8
方法五:
主配置文件编写
banner.charset=UTF-8
server.tomcat.uri-encoding=UTF-8
spring.messages.encoding=UTF-8
spring.freemarker.charset=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.forcr=true
spring.http.encoding.enabled=true
方法六:
设置@PropertySource的encoding为UTF-8
方法七:
将自定义内容从主配置文件中移动到自己建的配置文件中,并设置@PropertySource的读取文件路径
(如:
步骤1、application.properties配置文件中有自定义内容name=张三,将其删除。
步骤2、创建一个新的配置文件springboot.properties,写入自定义内容
步骤3、设置@PropertySource的读取文件路径为value="classpath:springboot.properties")