SpringBoot 配置文件中配置的中文,程序读取出来是乱码的解决
配置文件中是正常显示的中文,但是spring读取到的确是乱码。
我总共有两种解决办法,
第一种方法:
先复制或者备份一下你的配置文件的所有字符,打开设置将transparentnative-to-asciiconversion选中,然后返回将之前的配置文件重新粘贴一遍(一定要将中文重新打一遍)如图:
Transparentnative-to-asciiconversion的意思是:自动转换ASCII编码。
他的工作原理是:在文件中输入文字时他会自动的转换为Unicode编码,然后在idea中发开文件时他会自动转回文字来显示。
这样做是为了防止文件乱码。。。
OK,大概意思就是这样,这个文件你虽然看起来没问题,但是你只要选中了它,他么他现在就是一个ASCII文件存储在你本地,但是git上的文件可不是这个格式,你可以尝试用notepad++打开这个本地的.properties文件,你会发现他没有中文,,
这样可能会导致一个问题,git提交后中文字符会乱码https://www.nhooo.com/article/195655.htm
第二种方法:
这个方法呢很简单就是直接在配置文件中将中文设置为Unicode编码,例如
spring.application-id=\u8863\u9f99\u5ddd
去网页找一个中文转成Unicode码的网站,直接进行转换
补充知识:springboot项目执行出现中文乱码(从本地运行到打war包)
前言:中文乱码问题
一,本地运行
就是直接使用springboot内嵌的tomcat运行出现中文乱码的问题
(1)参考如下pom.xml的配置文件加入jvm启动参数。
-Dfile.encoding=UTF-8
(2)具体加的位置如下
org.springframework.boot spring-boot-maven-plugin true -Dfile.encoding=UTF-8 org.springframework springloaded 1.2.5.RELEASE
二,打成war包乱码解决
问题描述
今天在使用maven打包springboot项目上线时,遇到一个坑,项目本地启动中文是没有乱码的,但是当我把打包好的jar,扔向服务器时运行时,中文全部乱码,开始还以为是liuxn本身一些配置我没有配置好,后来经过测试,打包的jar文件本身中文就已经乱码,下面为本人调试修改后可以正常打包可执行jar并中文不乱码的pom.xml配置文件。
org.apache.maven.plugins maven-compiler-plugin 1.8 1.8 utf-8 org.springframework.boot spring-boot-maven-plugin com.zhenqinl.StartupApplication repackage
三,结尾给大家一个神坑Tomcat报错
严重:UnabletoprocessJarentry[META-INF/versions/9/module-info.class]fromJar[jar:file:/E:/eclipse-workspace/.metadata/.plugins
/org.eclipse.wst.server.core/tmp1/wtpwebapps/GymSystem/WEB-INF/lib/log4j-api-2.11.1.jar!/]for
annotationsorg.apache.tomcat.util.bcel.classfile.ClassFormatException:Invalidbytetaginconstantpool:19at
org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:136)atorg.apache.tomcat.util.bcel.classfile.ConstantPool.
(ConstantPool.java:59)at
org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:208)at
org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:118)at
org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2055)at
org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1931)at
org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfi
g.java:1897)atorg.apache.catalina.startup.ContextConfig.pro
本人是直接下载一个Tomcat解决问题的,出现这个问题就是Tomcat的问题。
以上这篇SpringBoot配置文件中配置的中文,程序读取出来是乱码的解决就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。