【fastjson】java.lang.IllegalStateException Failed to introspect Class

【报错】Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.util.DefaultPrettyPrinter


参考1

参考2

参考3

  • 把原来SSM项目里的jackson换成fastjson后,开始报错

Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.util.DefaultPrettyPrinter

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.http.converter.json.MappingJackson2HttpMessageConverter#0'


  • 检查后发现是在spring-mvc.xml里配置了这个,这个乱码过滤器是对应jackson的,且配置了@ResponseBody是由jackson解析的

    	  <!--JSON乱码问题配置-->
            <mvc:annotation-driven>
               <mvc:message-converters register-defaults="true">
                    <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                        <constructor-arg value="UTF-8"/>
                    </bean>
                    <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                        <property name="objectMapper">
                            <bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean">
                                <property name="failOnEmptyBeans" value="false"/>
                            </bean>
                        </property>
                    </bean>
                </mvc:message-converters>
            </mvc:annotation-driven>
    

  • 使用fastjson的,配置这个乱码过滤器

    	<!--配置@ResponseBody由fastjson解析,以及乱码过滤-->
    	<mvc:annotation-driven>
            <mvc:message-converters register-defaults="true">
                <!-- 配置Fastjson支持 -->
                <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                            <value>application/json</value>
                        </list>
                    </property>
                    <property name="features">
                        <list>
                            <value>WriteMapNullValue</value><!--是否输出值为null的字段,默认为false -->
                            <value>QuoteFieldNames</value><!--输出key时是否使用双引号,默认为true -->
                        </list>
                    </property>
                </bean>
            </mvc:message-converters>
        </mvc:annotation-driven>
    
posted @ 2021-04-09 17:45  musecho  阅读(346)  评论(0编辑  收藏  举报