遇到奇怪的问题,使用@ResponseBody注解,返回数据的时候出错,报错信息为数组越界。
原因为,responsebody标签spring在处理的时候,在StringHttpMessageConverter类中写如了过多的charset,写入部分的代码如下。
然后就在
StreamUtils.copy(s, charset, outputMessage.getBody());
这里的时候数组越界了,因为被tomcat截取了head的部分内容。
相关内容看https://jira.springsource.org/browse/SPR-7316
解决方式1或者2或者3
1、配置spring默认写入头部的编码。
2、配置连接器的最大http头部分大小。默认是4k。
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="utf-8" maxHttpHeaderSize="8192"/>3、升级spring版本
spring启动的时候初始化,这个
AnnotationMethodHandlerAdapter
的时候
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
把原来的配置修改为false。
AnnotationMethodHandlerAdapter中设置的地方如下。
![](http://dl2.iteye.com/upload/attachment/0088/9948/d6fbc32e-58b8-386f-a03d-16ef30cace1c.png)
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>把原来的配置修改为false。 AnnotationMethodHandlerAdapter中设置的地方如下。
![](http://dl2.iteye.com/upload/attachment/0088/9948/d6fbc32e-58b8-386f-a03d-16ef30cace1c.png)