博客项目BUG集

这篇博客汇总了作者在项目中遇到的一系列错误及解决方案,包括导入数据库SQL文件时的版本问题,使用Spring Email发送邮件的身份验证问题,发送邮件的用户未找到问题,模板解析错误,SQL语法错误,评论显示问题,以及Spring整合Redis时的依赖注入问题。每部分详细描述了问题的症状和解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题集

1.导入外部数据库SQL文件出现错误

  1. 导入外部数据库时出现问题:Invalid default value for ‘gmt_create’ ,截图如下:在这里插入图片描述在这里插入图片描述
    通过查询得知这是一个很常见的版本差异问题:
解决方案
  • 方案一:重装MySQL数据库,版本选择5.7或者5.7以上的版本(因为我的版本为5.5.28版本,版本小于5.6的会出现这个错误)
  • 方案二:
    这个错误的主要原因,是因为给了时间字段的列默认值一个 CURRENT_TIMESTAMP 默认值,而这个默认值在低版本的 MySQL 中是不支持的,因此就出现了题目中的这个报错,所以呢,把每个时间字段的默认值修改一下即可,比如:

DROP TABLE IF EXISTS `bl_about`;

CREATE TABLE `bl_about` (
  `about_id` varchar(32) NOT NULL COMMENT '帖子id',
  `about_title` varchar(63) DEFAULT NULL COMMENT '标题',
  `about_content` mediumtext COMMENT '帖子内容',
  `about_read` int(11) DEFAULT '0' COMMENT '阅读数',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
  `about_version` int(11) DEFAULT '1' COMMENT '乐观锁',
  `is_deleted` int(1) DEFAULT '0' COMMENT '是否删除,0否1是',
  PRIMARY KEY (`about_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='关于闲言表';

更改为:

DROP TABLE IF EXISTS `bl_about`;

CREATE TABLE `bl_about` (
  `about_id` varchar(32) NOT NULL COMMENT '帖子id',
  `about_title` varchar(63) DEFAULT NULL COMMENT '标题',
  `about_content` mediumtext COMMENT '帖子内容',
  `about_read` int(11) DEFAULT '0' COMMENT '阅读数',
  `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
  `gmt_modified` datetime DEFAULT NULL COMMENT '更新时间',
  `about_version` int(11) DEFAULT '1' COMMENT '乐观锁',
  `is_deleted` int(1) DEFAULT '0' COMMENT '是否删除,0否1是',
  PRIMARY KEY (`about_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='关于闲言表';

全部的时间都更改完毕,则可以正常导入

2. 测试发送邮件

我采用的发送邮箱方式为 Spring Email 发送邮件,邮箱采用 新浪邮箱
邮箱配置为:(注,此为正确配置)

# MailProperties 邮箱参数配置
spring.mail.host=smtp.sina.com
spring.mail.port=465
spring.mail.username=我的账号
#采用授权码作为密码
spring.mail.password=授权码
spring.mail.protocol=smtps
#这里的意思是发送邮件的时候是采用ssl安全连接的
spring.mail.properties.mail.smtp.ssl.enable=true

问题描述

报错问题:org.springframework.mail.MailAuthenticationException: Authentication failed
用Spring发送邮件的出现这个错误,代码如下:
在这里插入图片描述
问题提示为我的身份验证失败

# MailProperties 邮箱参数配置
spring.mail.host=smtp.sina.com
spring.mail.port=465
spring.mail.username=我的账号
spring.mail.password=我的密码
spring.mail.protocol=smtps
#这里的意思是发送邮件的时候是采用ssl安全连接的
spring.mail.properties.mail.smtp.ssl.enable=true

解决方案

将我的密码改为 采用授权码作为密码 ,也就是上面提到的正确配置

3. 发送邮件出现错误

在这里插入图片描述

问题描述

554 User not found;
问题出现为在测试注册任务时,显示用户无法找到,产生系统回退邮件

解决方案

这是因为,在测试注册时,我填写的邮箱名为一个虚拟的,就如上的收件人,muyiupup5@sina.com根本没有这一个邮箱,所以才会产生一个邮件退回现象,在填写正确的邮箱(如我自己的QQ邮箱)之后,邮件正常发送;

4. 测试拦截时出现错误

问题:An error happened during template parsing (template: “class path resource [templates//index.html]” - line 47, col 71)
在这里插入图片描述
页面显示:在这里插入图片描述

问题描述

这个问题出现在设置拦截时,对于主页面的设置中,产生了一个错误,由图可以看到问题出现在index页面的 47 行

解决方案

查看index页面中 47 行前后,可以看到
在这里插入图片描述
在第二个标注点中,可以发现少写了一个双引号,添加之后,问题解决!!

5. 编写发布帖子时出现错误

问题描述

在进行发布帖子的功能变现时,测试中出现,显示了发布成功,但是在页面上并没有看到新发布的贴子,同时在控制台上出现报错
Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
在这里插入图片描述
这是我的任务日志显现,控制台报错问题描述也一样,其实这里不难看出,是我的SQL语句出现了问题,在查看SQL语句之后发现了问题,
在这里插入图片描述
在编写SQL插入语句时,**#将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号。而 ** 这一个会将传入的数据直接显示生成在sql中。
#方式能够很大程度防止sql注入;$方式无法防止Sql注入。

解决方案

将 $ 换成 # 能将问题解决!!

6. 在实现显示评论时出现错误

问题描述

Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: “rvo.target==null” (template: “/site/discuss-detail” - line 153, col 43)

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field ‘target’ cannot be found on object of type ‘com.community.entity.Comment’ - maybe not public or not valid?
在这里插入图片描述
通过查看错误提示,错误显示在评论页面中;通过问题,看出我的target好像没有赋值,那么通过查看对应的 Controller 层,我找到了,我的 target 有值的,只是我没有把回复的值(target)提交到 评论的值中(commentVo),我提交的只是一个列表,所以导致了错误,看图:

在这里插入图片描述
这里打叉的为我的错误提交(应该提交一个回复的 Vo 列表 replyVoList,而不是一个 回复列表 replyList),这导致了我在前端页面判断的 target 存在值与否。

解决方案

问题出现在 前端页面上,那么首先我要去查看前端的代码是否出现一些简单的问题(代码写错啊之类的)
在前端代码没错的情况下,查看与前端代码请求相对应的 Controller 代码,通过查看逻辑判断,找到问题所在(注,从前端代码出错的位置去入手查找,解决问题的几率非常大)

解决:将回复(replyVo)装到 评论的 Vo 代码中修改
在这里插入图片描述
说多了就是运营得稀烂,两个字母的问题,解决了半个小时。

7. 在spring整合redis时,测试redis出现错误

问题描述

在测试redis输入数据时,出现无法找到
**nsatisfied dependency expressed through method ‘redisTemplate’ parameter 0;**当然,这只是一段描述,之后我在解决这个问题后,再以相同的错误代码去运行,但问题又没有了,就很迷惑,所以,还是决定记录下来

2021-04-19 20:33:45,306 ERROR [main] o.s.b.SpringApplication [SpringApplication.java:856] Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisTemplate' defined in class path resource 
[com/community/config/RedisConfig.class]: Unsatisfied dependency expressed through method 'redisTemplate' parameter 0; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' 
defined in class path resource [org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.class]: Bean instantiation 
via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[org.springframework.data.redis.connection.jedis.JedisConnectionFactory]: Factory method 'redisConnectionFactory' threw exception; 
nested exception is java.lang.NoClassDefFoundError: redis/clients/jedis/util/Pool

问题的解决

问题出现在我的pom.xml文件的包导入问题上
原先的问题:

<dependency>
     <groupId>org.springframework.data</groupId>
     <artifactId>spring-data-redis</artifactId>
</dependency>

换成:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    <exclusions>
       <exclusion>
            <groupId>io.lettuce</groupId>
            <artifactId>lettuce-core</artifactId>
       </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
</dependency>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值