[alibaba/fastjson]spring 4.3版本初始化错误

2024-05-22 312 views
9

版本1.2.70

Caused by: java.lang.NoSuchFieldError: UTF8 at com.alibaba.fastjson.support.config.FastJsonConfig.(FastJsonConfig.java:86) at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.(FastJsonHttpMessageConverter.java:73) at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4.(FastJsonHttpMessageConverter4.java:18) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ... 47 more

回答

6
<bean id="fastJsonHttpMessageConverter"
    class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4">
    <property name="supportedMediaTypes">
        <list>
            <value>text/html;charset=UTF-8</value>
            <value>application/json;charset=UTF-8</value>
        </list>
    </property>
    <property name="fastJsonConfig">
        <bean class="com.alibaba.fastjson.support.config.FastJsonConfig">
            <property name="serializerFeatures">
                <list>
                    <value>WriteDateUseDateFormat</value>
                    <value>BrowserCompatible</value>
                </list>
            </property>
            <property name="features">
                <list>
                    <value>AllowArbitraryCommas</value>
                    <value>AllowUnQuotedFieldNames</value>
                    <value>DisableCircularReferenceDetect</value>
                </list>
            </property>
        </bean>
    </property>
</bean>

配置如上,已排除包冲突,但是还是报UTF8错误

0

@wenshao @VictorZeng 麻烦看一下,感谢。版本已升级至最新的1.2.72,问题仍然存在

6

应该还是包冲突问题,排除一下多余依赖

4

有什么比较好的办法排除多余依赖?

7
<exclusions>
    <exclusion>
        <groupId>*</groupId>
        <artifactId>*</artifactId>
    </exclusion>
</exclusions>
2

按照上述方法排除过了的,通过mvn dependency:tree检查,也只有1个fastjson的jar,但是问题还是存在

3

再次使用enforcer检查了所有的重复依赖,去除后问题依旧

2

@wenshao @VictorZeng 麻烦看一下,感谢。这个问题排除了很久,依赖都全部检查了问题还是存在

5

@wenshao @VictorZeng 麻烦看一下,感谢。这个问题排除了很久,依赖都全部检查了问题还是存在

您好,您最后是怎么解决这个问题的呢

7

@wenshao @VictorZeng 麻烦看一下,感谢。这个问题排除了很久,依赖都全部检查了问题还是存在

您好,您最后是怎么解决这个问题的呢

应该还是依赖冲突的问题,排一下依赖看看,再检查一下运行环境。

4

@wenshao @VictorZeng 麻烦看一下,感谢。这个问题排除了很久,依赖都全部检查了问题还是存在

您好,您最后是怎么解决这个问题的呢

应该还是依赖冲突的问题,排一下依赖看看,再检查一下运行环境。

依赖都排除了,但还是报这个问题,SpringBoot版本是2.0.4.RELEASE

5

@wenshao @VictorZeng 麻烦看一下,感谢。这个问题排除了很久,依赖都全部检查了问题还是存在

您好,您最后是怎么解决这个问题的呢

应该还是依赖冲突的问题,排一下依赖看看,再检查一下运行环境。

依赖都排除了,但还是报这个问题,SpringBoot版本是2.0.4.RELEASE

可以跟进源码里面看一下 UTF8 这个字段是否存在