工作中的一些小总结(5) - 遇到的各种报错异常

关于一些报错异常

控制台报:

1.java.lang.IllegalArgumentException: Malformed \uxxxx encoding

解决方法: properties中不能含有\符号. 只要遇到就会报上面的错误. 解决方式:将properties中的\改为\\或者/.就行了.


2.日志报错

log4j:ERROR Category option " 1 " not a decimal integer
log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{ 1 }:%L - %m%n

将{1}里面的空格去掉:

log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{1}:%L - %m%n

3.Excel导出 报错The workbook already contains a sheet named (文件名重名)

poi导出excel,只允许sheetName 有31个字符 Excel中sheet命名有如下规则: (1)sheet名称不能多于31个(包含英文、汉字、| 、()等,但是不能包含: 、/、?、*、[]等 ),程序中使用poi工具来生成的时候,传进去大于31个长度的字符串时,会被自动截取,便会导致两个名字变为一样的,出现sheet同名异常

4.接口使用 @GetMapping() 且有入参时,出现 Request method 'POST' not supported 的错误

项目中使用springcloud分布式框架,在openfeign中,调用其他微服务接口,使用@GetMapping()接口参数必须要加@RequestParam("xxx"),
否则就会报 Request method 'POST' not supported 的错误

5.接口调用时使用@RequestParam,出现 Required String parameter 'xx' is not present 的bug

当接口上使用@RequestParam时,传递的参数若是空 会报错 Required String parameter 'penaltyStaffId' is not present

原因是 @RequestParam 里required 默认为 true 即表示不能为空
解决方法:
1.required 设置为false 不校验参数是否是空
2.在接口调用前判断参数是否为空

6.spring boot上传文件错误 The temporary upload location [/tmp/tomcat.******/work/Tomcat/localhost/ROOT] is not valid

出现原因及解决方法

System.getProperty("java.io.tmpdir") 获取的路径在linux是 /temp 路径下
(1)、SpringBoot项目启动后,系统默认会在 /tmp 目录下自动创建如下三个目录
hsperfdata_root,
tomcat.***.8080,(结尾是项目的端后)
tomcat-docbase.
.8080
(2)、Multipart(form-data)的方式处理请求时,默认就是在第二个目录下创建临时文件的
(3)、CentOS7 定时清理临时文件目录
可以通过命令:

cat /usr/lib/tmpfiles.d/tmp.conf

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# See tmpfiles.d(5) for details

# Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 10d         #   清理/tmp下10天前的目录和文件
v /var/tmp 1777 root root 30d     #   清理/var/tmp下30天前的目录和文件

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp

解决方法
方法一
/tmp目录的清理规则主要取决于/usr/lib/tmpfiles.d/tmp.conf文件的设定:
我们可以配置这个文件,比如你不想让系统自动清理/tmp下以tomcat开头的目录,那么增加下面这条内容到配置文件中即可:

x /tmp/tomcat.*

方法二

#通过SpringBoot启动配置注解(@Configuration) 指定自有上传文件目录
@Configuration
public class MultipartConfig {
 
    /**
     * 文件上传临时路径
     */
    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        String location = System.getProperty("user.dir") + "/data/upload/tmp";
        File tmpFile = new File(location);
        if (!tmpFile.exists()) {
            tmpFile.mkdirs();
        }
        factory.setLocation(location);
        return factory.createMultipartConfig();
    }
}

方法三
修改application.yml

#指定临时目录
spring.servlet.multipart.location=/xx/xx

7. SVN:cleanup failed to process the following paths 错误的解决方案

今天在update的时候,报错:\.svn\pristine\b7\xxxx.svn-base”: 系统找不到指定的文件。 解决方法:首先用Navicat打开svn的数据库文件.svn/wc.db,然后删除lock和work_queue里的数据即可

8.项目启动中报错

Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'URL [jar:file:/usr/local/docker/rmcp/rmcp-service-schedule/rmcp-service-schedule-1.6.4.RELEASE.jar!/BOOT-INF/classes!/mapper/work/ScheduleWorkWorkPlanWeekMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalStateException: Mapping is missing column attribute for property null 多了一个空的result 标签

posted @ 2021-01-04 14:12  墨墨的成长  阅读(1663)  评论(0编辑  收藏  举报