各种问题
一.字符编码
本地idea启动正常,打成jar包在windows服务器上启动,带汉字的post请求,controller中用@RequestBody接收参数,转换的时候报错|:JSON parse error: Invalid UTF-8 start byte 0xa4
。
1.先排除了文件编码问题,都是统一的UTF-8,各处版本一致JDK1.8;
2.添加了启动参数:-Dfile.encoding=UTF8 、 -Dsun.jnu.encoding=UTF8
,仍然不行;
3.后排除springboot的tomcat,打成war包启动,设置tomcat编码UTF-8;
4.运行正常。
问题换个方式暂时解决了,但是还没弄清楚原因,jar运行仍不行。
windows默认编码GBK,Linux默认编码UTF-8
配置文件中swagger的分组配置中含有中文(UTF8),读取设置后因乱码了导致有重复的分组会导致报错
二.sh脚本调用失败
1.
通过java的 new ProcessBuilder().start()来调用 .sh 脚本文件
经常出现
java.io.IOException: Cannot run program "/home/xx/xx.sh": error=2, No such file or directory
开始一直不知道咋回事,因为我的.sh文件是直接复制的一个同位置的可正常执行的sh文件;
后面我直接在linux上直接运行.sh文件,发现报错-bash: ./xxx.sh: /bin/bash^M: bad interpreter: No such file or director
根据这个错误信息一搜,说的是sh脚本文件编码不对。
因为我的文件是在windows下复制改写的,所以文件结尾符是 dos
,所以在linux下无法运行;
linux系统需要 unix
。
解决方式:
vim xx.sh
:set ff=unix
最后wq保存即可。
2.
sh脚本执行没效果,后面发现是~/.bash_profile
这个文件里面没有配置。
这是个隐藏文件,直接在自己账号下 vim ~/.bash_profile
即可打开,配置好即可,具体怎么配置我也不懂,
我之前的配置如下:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH
export PATH
修改后的配置如下:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH