开发工作报错总结

4 篇文章 0 订阅

错误1:
Driver com.mysql.jdbc.Driver claims to not accept jdbcUrl, jdbc.mysql://localhost:3306/test?serverTimezone=UTC
错误原因:数据源的url地址写错了
正确写法:jdbc:mysql://localhost:3306/test?serverTimezone=UTC


错误2:
Caused by: com.mysql.cj.exceptions.UnableToConnectException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ‘;characterEncoding=UTF-8’.

错误原因:

数据源的url地址写错了,在XML中,符号&需要转义成&,而在properties文件中则不需要转义。

在Spring配置文件中的正确写法:

<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8"></property>

而在.properties外部配置文件中的正确写法:

jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8

错误3:
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
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

错误原因:
模块中添加了 mysql 的依赖后需要手动配置数据源
解决方法1:在配置文件中配置数据源:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/数据库名?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123456

解决方法2:在启动类的@SpringBootApplication注解上添加排除数据源配置的修饰:

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

错误4:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.atguigu.eduservice.mapper.EduCourseMapper.getPublishCourseInfo

错误原因:
由于maven的默认加载机制(将java文件夹里面的java类型文件进行编译后放入target目录中,如果是其他类型的文件则不会加载),所以 java目录中的 xml配置文件并没有被加载。

解决方式1:手动将 xml 文件复制到 target 目录中
解决方式2:将 xml 文件放到 resources 目录中
解决方式3(推荐):通过配置实现:
step1:

<build>
	<resources>
    	<resource>
        	<directory>src/main/java</directory>
        	<includes>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

step2:

# 配置mapper的xml文件的路径
mybatis-plus.mapper-locations=classpath:com/atguigu/eduservice/mapper/xml/*.xml

错误5:

前端上传文件至后台时报错:

POST http://localhost:9001/eduvod/video/uploadAliVideo 413 (Request Entity Too Large)
:9528/#/course/chapter/1343489458527301633:1 Access to XMLHttpRequest at ‘http://localhost:9001/eduvod/video/uploadAliVideo’ from origin ‘http://localhost:9528’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

错误原因:
nginx 所能接收的请求实体大小限制为默认1M,而上传文件大小超出了该限制

解决办法:
在 nginx.conf 文件中的 http{} 块中添加如下配置:

client_max_body_size	1024m;

错误6:

前端报错:
Access to XMLHttpRequest at ‘http://localhost:9001/eduvod/video/uploadAliVideo’ from origin ‘http://localhost:9528’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
后端报错:
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.

错误原因:上传的文件大小超出了springboot的默认限制
解决办法(Spring Boot 2.x):在配置文件中添加如下配置:

# 最大上传单个文件大小:默认1M
spring.servlet.multipart.max-file-size=1024MB
# 最大支持的请求大小 :默认10M
spring.servlet.multipart.max-request-size=1024MB

错误7:

Caused by: java.lang.IllegalStateException: Could not resolve element type of Iterable type @org.springframework.web.bind.annotation.RequestParam java.util.List<?>. Not declared?

错误原因:List<>没有指定泛型,不能提供转换
解决办法:给List<>加上泛型:

public void test(@RequestParam("idList") List<String> idList)

错误8:

测试阿里云短信服务时发送验证码报空指针异常

错误原因:阿里云接口更换了
解决办法:将以下方法

request.setMethod(MethodType.POST);

更换为:

request.setSysMethod(MethodType.POST);

错误9:

org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public com.atguigu.commonutils.R com.atguigu.educenter.controller.UcenterMemberController.loginUser(com.atguigu.educenter.entity.UcenterMember)

错误原因:Get 请求是 url 传参,无法获取请求体中的参数

解决办法:将 @GetMapping 更改为 @PostMapping


错误10:

Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String

错误原因:这是由于时间类型参数与字符串类型对比所引发的错误
如下例,时间参数类型与空字符串进行了对比:

<if test="queryMap.startTime != null and queryMap.startTime !=''">
	and i.gmt_create >= #{queryMap.startTime}
</if>

解决办法:去掉空字符串判断, 只保留非空判断即可

<if test="queryMap.startTime != null">
	and i.gmt_create >= #{queryMap.startTime}
</if>

错误10:

java.util.regex.PatternSyntaxException: Dangling meta character ‘+’ near index 0

错误原因:split方法转化字符串为数组时,字符串中带有“+”时,用“+”分隔字符串成数组是不正确的,因为+、*、|、\等符号在正则表达式中有相应的不同意义,所以在使用时要进行转义处理。
错误的写法如下:

keyword.split("+")

正确的写法是:

keyword.split("\\+")

错误11:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column ‘WSNR’ at row 1

错误原因:blob类型字段的最大存储限制是65535字节(64K少1字节),用户上传的文件大小超出了这个限制。
解决办法是将blob类型更换为:mediumblob(最大16M)或 longblob (最大4G)


错误12:

com.mysql.jdbc.PacketTooBigException: Packet for query is too large (53486309 > 1048576). You can change this value on the server by setting the max_allowed_packet’ variable.

错误原因:MySQL根据配置文件会限制Server接受的数据包大小。插入、更新或查询时数据包的大小会受 max_allowed_packet 参数限制,导致操作失败。

  • 查看 max_allowed_packet 配置参数的值:
show VARIABLES like '%max_allowed_packet%';

在这里插入图片描述
解决办法:修改该配置。


错误13:

项目启动编译时报如下错误:

Error:java: java.lang.OutOfMemoryError: WrappedJavaFileObject[org.jetbrains.jps.javac.InputFileObject[file:///E:/workspace-idea/court2022/src/main/java/tdh/court/sxzm/dao/EajSxzmqkDAO.java]]@pos3882: WrappedJavaFileObject[org.jetbrains.jps.javac.InputFileObject[file:///E:/workspace-idea/court2022/src/main/java/tdh/court/sxzm/dao/EajSxzmqkDAO.java]]@pos3889: WrappedJavaFileObject[org.jetbrains.jps.javac.InputFileObject[file:///E:/workspace-idea/court2022/src/main/java/tdh/court/sxzm/dao/EajSxzmqkDAO.java]]@pos3909: GC overhead limit exceeded

问题原因:编译的时候内存溢出了,需要修改idea的编译空间以增加编译时的内存最大值。

解决办法:将 idea 的 Build process heap size (Mbytes) 配置值增大
请添加图片描述

错误14:

访问页面时报如下错误:

Caused by: javax.servlet.jsp.JspTagException: Illegal use of <when>-style tag without <choose> as its direct parent at org.apache.taglibs.standard.tag.common.core.WhenTagSupport.doStartTag(WhenTagSupport.java:66)
at org.apache.jsp.webapp.sfpg.ajgl.bjyj.bjyj_jsp._jspService(bjyj_jsp.java:459)
… 31 more

问题原因:没有在<c:when></c:when><c:otherwise></c:otherwise>标签外包裹<c:choose></c:choose>

修改代码:
请添加图片描述

错误15:

只有字段才可以预编译!
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值