BUG库,列举我从今天开发遇到的BUG

  1. java.lang.IllegalArgumentException: Invalid character found in the request target
    在请求目标中发现的无效字符
    方法请求体传入非法参数
    一般是前台的锅
  2. java.lang.IllegalArgumentException: object is not an instance of declaring class
    由于没有实例化可以有如下两种方法:
    1、反射方法定义成为static的,故被反射类就不需要实例化;
    2、
    method.invoke(class.getDeclaredConstructor().newInstance(), args); 
    

3、 我解决的方法,本方法不用静态的就可以了
你本方法是静态的,需要反射的方法不是静态的,所以反射执行反射方法的时候肯定还没有初始化对象。把两个方法改一致就行了
3. nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
连接池中没有可用的jedis,没有正确关闭连接,连接池耗尽
properties文件里jedis的配置有问题,要么是写错了,要么是没设置好端口
增大连接数
4. nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘param’ in ‘class vip.xiaonuo.modular.safety.risk.param.SafetyRiskParam’
在这里插入图片描述找不到get方法,
当时在mapper层用的重载,想起来不能用,写了两个方法
5. java.io.IOException: 你的主机中的软件中止了一个已建立的连接
表单重复提交。
由于客户端在发送请求后,还没等服务器响应就断开了连接,有可能是因为网络原因,突然网断了,但是如果错误频繁出现的话,可能就是服务端的问题了。

有可能是后台处理时间太长了。

服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉。

客户关掉了浏览器,而服务器还在给客户端发送数据。
  1. java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    经典异常:数组下标越界,数组里没有足够多的数据
  2. Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error Type referred to is not an annotation type:xxx
    AOP中切点写错了
    在这里插入图片描述
  3. sql_mode=only_full_group_by
    在mysql执行查询分组过滤语句的时候报错
    原因:
    select 后面跟的字段没有全部在group by 中
    SELECT、HAVING、ORDER后的非聚合字段必须和GROUP BY后的字段保持完全一致
    解决方法:
    数据库配置文件中增加一行配置:配置要写在[mysqld]下面,否则不生效
    sql-mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

这是mysql5.7版本以后才会有的设置,需要编辑配置文件或者修改sql语句
或者使用sql语句禁用(mysql重启失效)

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
  1. Invalid bound statement (not found)
    我知道这个报错是应为mapper.xml文件没有扫描到
    于是我先看了xml的namespace是否有误,又看了mybatis的mapper-locations配置。
    发现均无问题。
    后来我看了target文件目录下,生成的class文件没有xml文件,知道打包没有将xml文件打包进去。pom文件资源打包拦截配置放开即可
   <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.yml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.yml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
  1. java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    原因:
    连不上mysql数据库了
  2. com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl and no properties discovered to create BeanSerializer
    原因:
    是我在mybatis中用了这样的写法
  <resultMap id="userRecord" type="vip.xiaonuo.modular.safety.train.exam.entity.vo.ExamUserListVO">
        <id property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="brand" column="brand"/>
        <result property="phone" column="phone"/>
        <collection property="scoreVOList"
                    ofType="vip.xiaonuo.modular.safety.train.exam.entity.vo.ExamUserScoreVO"
                    select="selectUserScore"
                    column="{trainUserId=id,examId=examId}"/>
    </resultMap>

mybatis配置懒加载导致RestController或responsebody返回对象Jackson解析失败
解决方法
在实体类前,即你返回需要jackson解析的类,前面添加注解,让Jackson序列化时忽略handler属性

@Data
@JsonIgnoreProperties(value = "handler")
public class ExamUserListVO {
    private Long id;
    private String name;
    private String brand;
    private Integer phone;

    private List<ExamUserScoreVO> scoreVOList;
  1. Statement cancelled due to timeout or client request
    sql执行时间过长,超过客户端连接时间
    解决方法:
    连接数据库是增加参数:queryTimeout=3000,不行再增加
    优化查询,使用索引,排序操作可以放在内存中排序

  2. IORuntimeException
    IO运行时异常,常用于对IOException的包装

  3. java.io.EOFException: Unexpected EOF read on the socket
    原因:
    前端mock把requestBody给消费掉了,导致传到后端没有body,后端在解析的时候发现request请求头的content-length是59,就一直等待接收数据,与此同时,前端也在等待后端返回结果。1分钟后,前端等待超时,前端发EOF请求(具体为何会发EOF还需要进一步学习),后端收到以后,发现和预期的消息不一致,就报了EOF这个错误。
    解决方法:
    让前端改

  4. class path resource [xx] cannot be resolved to absolute file path because it does not reside
    原因:
    在springBoot下放入静态文件,编译器运行测试时可以拿到,一打成jar文件就报错
    这是因为:在jar文件中,不能直接通过文件资源路径拿到文件,但是可以在jar包中拿到文件流。(一定要用流,不要尝试去拿到绝对路径,否则报错!
    解决方法:
    之前的写法:

  @Override
    public void exportTemplate(HttpServletResponse response) {
        // 读取本地的文件
        String filePath = "/template/金鹰安全-隐患导入模板.xlsx";
        ClassPathResource readFile = new ClassPathResource(filePath);

        // 获取文件对象
        File file = null;
        try {
            file = readFile.getFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 获取文件流
        DownloadUtil.download(file, response);
    }

所以改变写法:

   @Override
    public void exportTemplate(HttpServletResponse response) {
        String filePath = "/template/金鹰安全-隐患导入模板.xlsx";
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        try {
            org.springframework.core.io.Resource[] resources = resolver.getResources(filePath);
            org.springframework.core.io.Resource resource = resources[0];
            InputStream stream = resource.getInputStream();

            File file = new File(filePath);
            FileUtils.copyToFile(stream, file);
            DownloadUtil.download(file, response);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
  1. org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class vip.xiaonuo.core.pojo.response.ErrorResponseData] with preset Content-Type ‘video/mp4’
    原因:
    请求Content-type 未传入或者与返回的response的Content-type不一致
    解决方法:
    将请求的Content-type 与返回的Content-type 保持一致
  2. org.springframework.web.multipart.MultipartException: Current request is not a multipart request
    前端需要把Content-Type设置成multipart/form-data或着去掉Content-Type
  3. MySQL You can’t specify target table ‘prevention_danger_record’ for update in FROM clause
    sql如下:
delete from prevention_danger_record where id in (
SELECT prevention_danger_record.id from prevention_danger_record  LEFT JOIN prevention_danger_task  on prevention_danger_record.check_task_id = prevention_danger_task.id where prevention_danger_task.id is null
);

意思是要删除再另一张关联表中没有匹配到的脏数据。
但是mysql不允许这样操作,需要在写一层select包装一下
正确的sql如下

delete from prevention_danger_record where id in (
SELECT id from  (
SELECT prevention_danger_record.id from prevention_danger_record  LEFT JOIN prevention_danger_task  on prevention_danger_record.check_task_id = prevention_danger_task.id where prevention_danger_task.id is null
) as a
);
  1. The bean ‘xxx‘ could not be injected as a ‘xxx‘because it is a JDK dynamic proxy that implements错误解决
    我的错误是这样发生的
    在这里插入图片描述在这里插入图片描述
    这两个不同的类,使用@Resource注入的时候使用的相同的名称 examQuestionMapper。由于@Resource注入的时候默认是byName,导致注入错误
    在这里插入图片描述解决方法:
    修改名字,使其不同
    使用@Autowired
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值