记录springboot遇到的一些错误

一、关于Thymeleaf的错误

1、An exception was raised while trying to serialize object to JavaScript using Jackson

报错信息如下:

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/list.html]")
Caused by: org.attoparser.ParseException: An error happened during template rendering
Caused by: org.thymeleaf.exceptions.TemplateOutputException: An error happened during template rendering
Caused by: org.thymeleaf.exceptions.TemplateOutputException: An error happened during template rendering
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: An exception was raised while trying to serialize object to JavaScript using Jackson
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 
    No serializer found for class java.util.logging.ErrorManager and no properties discovered to create BeanSerializer 
    (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

报错分析:
(1)主要需要注意两个错误信息:

  • An exception was raised while trying to serialize object to JavaScript using Jackson
  • to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS

(2)引起这种报错的原因有很多,我这里出现的问题是在Thymeleaf模版页面里使用[[${user}]]获取user,因为后台没有传过来user,user是空的,所以报错,报错推荐解决方案是:禁用SerializationFeature.FAIL_ON_EMPTY_BEANS

<script>
    var user = [[${user}]];
    alert(user)
</script>

解决方案:将报错分析中(2)出现错误的地方删掉,如果可以获取到则不会报错。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容