记录遇到的第二次异常java.lang.IllegalArgumentException

异常情况记录遇到的第二次异常java.lang.IllegalArgumentException

异常原因

SpringMvc使用@ResponseBody会自动把数据封装成json格式,但是需要手动添加依赖

解决办法

1.maven添加:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.4.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.4.3</version>
</dependency>

2.spring.xml文件配置如下:

<!-- 启动Springmvc注解驱动 -->
    <mvc:annotation-driven/>
 <!-- 返回json 方法一 需要导入 fastjson.jar包 -->  
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="false">
            <!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
            <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <!-- 这里顺序不能反,一定先写text/html,不然ie下出现下载提示 -->
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

解决办法来源