项目调试Bug集锦(更新中)

1.解决Error: Syntax error, unrecognized expression

报错信息

 jquery-1.11.3.min.js:2 Uncaught Error: Syntax error, unrecognized expression: #mnn').load('/view/banner.jsp')

 1 jquery-1.11.3.min.js:2 Uncaught Error: Syntax error, unrecognized expression: #mnn').load('/view/banner.jsp')
 2     at Function.ga.error (jquery-1.11.3.min.js:2)
 3     at ga.tokenize (jquery-1.11.3.min.js:2)
 4     at ga.select (jquery-1.11.3.min.js:2)
 5     at Function.ga [as find] (jquery-1.11.3.min.js:2)
 6     at m.fn.init.find (jquery-1.11.3.min.js:2)
 7     at new m.fn.init (jquery-1.11.3.min.js:2)
 8     at m (jquery-1.11.3.min.js:2)
 9     at HTMLAnchorElement.<anonymous> (bootstrap.min.js:6)
10     at HTMLDocument.dispatch (jquery-1.11.3.min.js:4)
11     at HTMLDocument.r.handle (jquery-1.11.3.min.js:4)

解决方案

因为在href跳转的标签中出现了触发模态框,把这个删掉就可以了data-toggle="modal"


2.解决Error starting ApplicationContext. 

报错信息 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 

[WARN] 2019-08-14 23:24:24 Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bannerController': Unsatisfied dependency expressed through field 'bannerService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.baizhi.service.BannerService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
[INFO] 2019-08-14 23:24:24 Stopping service [Tomcat] 
[WARN] 2019-08-14 23:24:24 The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43) 
[INFO] 2019-08-14 23:24:24 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 
[ERROR] 2019-08-14 23:24:24 
***************************
APPLICATION FAILED TO START
***************************
Description:
Field bannerService in com.baizhi.controller.BannerController required a bean of type 'com.baizhi.service.BannerService' that could not be found.
The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.baizhi.service.BannerService' in your configuration

解决方案

resources配置问题:application.yml 或application.properties文件扫描不到,将配置文件全部放在resources文件夹下,官方文档也建议将配置文件放在此文件夹下,但是就是找不到我的数据库配置文件,具体原因暂时还不明白。

把application.yml 或application.properties文件放在src/main/java下 就可以了

 


3.解决MaxUploadSizeExceededException

报错信息

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed;
nested exception is 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 cover exceeds its maximum permitted size of 1048576 bytes.] with root cause

解决方案

在yml文件中设置上传文件大小

 spring:
  servlet:
     multipart:
       enabled: true
       max-file-size: 50MB
       max-request-size: 50MB

4.解决UnexpectedRollbackException

最近在项目中发现了一则报错:“org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only”。根据报错信息来看是springboot框架中的事务管理报错:事务回滚了,因为它被标记为回滚状态。

 

报错原因

多层嵌套事务中,如果使用了默认的事务传播方式,当内层事务抛出异常,外层事务捕捉并正常执行完毕时,就会报出rollback-only异常。

解决方案


  • 如果希望内层事务抛出异常时中断程序执行,直接在外层事务的catch代码块中抛出e.
  • 如果希望程序正常执行完毕,并且希望外层事务结束时全部提交,需要在内层事务中做异常捕获处理。
  • 如果希望内层事务回滚,但不影响外层事务提交,需要将内层事务的传播方式指定为PROPAGATION_NESTED。注:PROPAGATION_NESTED基于数据库savepoint实现的嵌套事务,外层事务的提交和回滚能够控制嵌内层事务,而内层事务报错时,可以返回原始savepoint,外层事务可以继续提交。

 

事务传播方式


事务传播方式说明
PROPAGATION_REQUIRED 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中。这是默认的传播方式
PROPAGATION_SUPPORTS 支持当前事务,如果当前没有事务,就以非事务方式执行
PROPAGATION_MANDATORY 使用当前的事务,如果当前没有事务,就抛出异常
PROPAGATION_REQUIRES_NEW 新建事务,如果当前存在事务,把当前事务挂起
PROPAGATION_NOT_SUPPORTED 以非事务方式执行操作,如果当前存在事务,就把当前事务挂起
PROPAGATION_NEVER 以非事务方式执行,如果当前存在事务,则抛出异常
PROPAGATION_SUPPORTS 支持当前事务,如果当前没有事务,就以非事务方式执行。
PROPAGATION_NESTED 如果当前存在事务,则在嵌套事务内执行。如果当前没有事务,则执行与PROPAGATION_REQUIRED类似的操作。

 


5. D:Workspacessrcmainwebappimage (拒绝访问)

报错信息

修改数据时,如果不改动文件,只改动其他数据,就会报以下错误信息

 D:WorkspacesIDEACodeprojectsrcmainwebappimage (拒绝访问。)

错误原因以及解决

当上传文件为空时,不仅需要在修改时判断该字段为空,为其设置一个null以避免数据库修改该字段,还需要再上传的文件的upload方法中判断文件的原始文件名是否为空,如果为空就不做upload里面的修改操作,如果不做判断,当修改提交后执行aftersubmit就会进入upload方法执行修改。(这里upload主要是修改路径信息方便前台的展示)。


6.解决.DataIntegrityViolationException

报错信息

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: 

错误原因及解决

数据库字段和实体类字段 不一致

原文地址:https://www.cnblogs.com/xiaoyinger/p/11355663.html