请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

前端传过来的base64大小超过后端能解析的最大值

前端传到后端的base64字符串太大,超出了JSON的最大值,要怎么规避这个问题?前端已经配置成10M一个shard了。
图片描述

后端log:

38.284 WARN  o.s.w.s.m.s.DefaultHandlerExceptionResolver:207  Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: String length (5043368) exceeds the maximum length (5000000)]
30.953 WARN  o.s.w.s.m.s.DefaultHandlerExceptionResolver:207  Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: String length (5043368) exceeds the maximum length (5000000)]
41.037 INFO  c.n.d.s.r.a.ConfigClusterResolver:43   Resolving eureka endpoints via configuration
41.041 INFO  c.n.d.s.r.a.ConfigClusterResolver:43   Resolving eureka endpoints via configuration
14.965 WARN  o.s.w.s.m.s.DefaultHandlerExceptionResolver:207  Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: String length (5043368) exceeds the maximum length (5000000)]
41.042 INFO  c.n.d.s.r.a.ConfigClusterResolver:43   Resolving eureka endpoints via configuration

正在回答 回答被采纳积分+3

2回答

提问者 慕运维6519169 2023-07-20 18:23:14

问题已解决。com.fasterxml.jackson版本引起。学习的时候已经是2023年7月,前端后端所依赖的版本已经和开课的时候差别很大。为了更加贴近项目需求,后端微服务采用的是spring boot 3.1.0版本,其依赖的fasterxml.jackson是2.15.0。自2.15.0起,Jackson对字符串大小作出限制,不能超过5M,具体参见:https://github.com/FasterXML/jackson-core/issues/1001

目前绕过的办法是在Application内增加对Jackson的bean的配置。下面配置允许最大的字符串长度是100M。

// FileApplication.java
//jackson2.15 bug
    @Bean
    Jackson2ObjectMapperBuilderCustomizer customStreamReadConstraints() {
        return (builder) -> builder.postConfigurer((objectMapper) -> objectMapper.getFactory()
                .setStreamReadConstraints(StreamReadConstraints.builder().maxNestingDepth(2000).maxStringLength(100_000_000).build()));
    }


2 回复 有任何疑惑可以回复我~
  • 甲蛙 #1
    点赞!点赞!
    回复 有任何疑惑可以回复我~ 2023-07-21 17:34:46
提问者 慕运维6519169 2023-07-18 20:54:45

前端的分片已经切割为10M每片。

0 回复 有任何疑惑可以回复我~
  • 甲蛙 #1
    切成1M试试,太大也占用太多带宽,不符合实际
    回复 有任何疑惑可以回复我~ 2023-07-18 21:08:04
  • 提问者 慕运维6519169 回复 甲蛙 #2
    已经找到问题,是fasterXml的版本引起的。具体写在回答里,供后来的同学参考。
    回复 有任何疑惑可以回复我~ 2023-07-20 18:12:13
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号