分享一些在项目中遇到的错误以及解决方法

发布于:2022-12-24 ⋅ 阅读:(722) ⋅ 点赞:(0)

在这里插入图片描述

前言

众所周知,我们编写代码会产生各种各样的错误,俗称bug,下面我为大家列举出几种非常常见bug以及解决方案,大家碰到错误可以过来对比查看!

正文

  • Spring Boot项目默认是开启了自动配置的,当添加了以上数据库编程的依赖项时,就会自动从配置文件中读取连接数据库的URL参数值,如果当前尚未配置此参数,就会启动失败!

    错误如下:

    ***************************
    APPLICATION FAILED TO START
    ***************************
    
    Description:
    
    Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
    
    Reason: Failed to determine a suitable driver class
    
  • 如果Spring Boot数据库配置的spring.datasource.url中的主机名(localhost)或端口号(3306)错误,或者,MySQL / MariaDB的服务根本没有启动,则会出现以下错误:

    com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
    
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    
  • 如果在Spring Boot数据库配置的spring.datasource.url中指定的数据库名称有误,或MySQL / MariaDB中确实无此数据库,则会出现以下错误:

    java.sql.SQLSyntaxErrorException: Unknown database 'mall_qms'
    
  • 如果在Spring Boot数据库配置的spring.datasource.url中指定的serverTimezone有误,则会出现以下错误:

    java.sql.SQLNonTransientConnectionException: Could not create connection to database server.
    
    Caused by: java.time.zone.ZoneRulesException: Unknown time-zone ID: Asia/ShangHai
    
  • 如果在Spring Boot数据库配置的spring.datasource.usernamespring.datasource.password中配置的MySQL / MariaDB的用户名或密码错误,则会出现以下某种错误:

    java.sql.SQLException: Access denied for user 'rootx'@'localhost' (using password: YES)
    
    java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
    
    java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
    
  • 如果没有在配置类中正确的使用@MapperScan配置Mapper接口的根包,将出现以下错误:

    org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'cn.tedu.csmall.product.mapper.BrandMapper' available: expected at least 1 bean which qualifies as autowire candidate.
    
  • 如果:

    • 此前没有在application.properties中正确的配置XML文件的位置
    • 在XML中的<mapper>标签上配置的namespace值有误
    • 在XML中的<insert>等标签上配置的id值有误

    将出现以下错误:

    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.tedu.csmall.product.mapper.BrandMapper.insert
    
  • 如果使用过期的JWT,在解析时将出现错误:

    io.jsonwebtoken.ExpiredJwtException: JWT expired at 2022-09-06T17:33:03Z. Current time: 2022-09-08T09:04:26Z, a difference of 142283930 milliseconds.  Allowed clock skew: 0 milliseconds.
    
  • 如果使用的JWT数据的签名有误,在解析时将出现错误:

    io.jsonwebtoken.SignatureException: JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.
    
  • 如果使用的JWT数据格式有误,在解析时将出现错误:

    io.jsonwebtoken.MalformedJwtException: Unable to read JSON value: {"alg	!L��؈�������)]P�
    

持续更新中…

本文含有隐藏内容,请 开通VIP 后查看