Open suciver opened 4 years ago
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
... 27 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.alibaba.fastjson.support.config.FastJsonConfig]: Factory method 'fastJsonConfig' threw exception; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 40 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
at com.alibaba.fastjson.serializer.SerializeConfig.
当在项目中使用fastjson.properties设置 fastjson.asmEnable=false 此时如果没有先加载com.alibaba.fastjson.JSON类,而是直接调用SerializeConfig.getGlobalInstance()或者new SerializeConfig都会报 Exception in thread "main" java.lang.ExceptionInInitializerError at com.alibaba.fastjson.serializer.SerializeConfig.(SerializeConfig.java:67)
at com.alibaba.fastjson.serializer.SerializeConfig.(SerializeConfig.java:301)
at com.alibaba.fastjson.serializer.SerializeConfig.(SerializeConfig.java:293)
at com.alibaba.fastjson.serializer.SerializeConfig.(SerializeConfig.java:53)
at AppTest.main(AppTest.java:108)
Caused by: java.lang.NullPointerException
at com.alibaba.fastjson.JSON.config(JSON.java:130)
at com.alibaba.fastjson.JSON.(JSON.java:99)
... 5 more
看了SerializeConfig类的定义中有依赖com.alibaba.fastjson.JSON的类,而在使用fastjson.asmEnable=false时,JSON类在加载过程中就会调用SerializeConfig.getGlobalInstance()进行实例化动作,这种情况下程序入口如果没有加载完成com.alibaba.fastjson.JSON类直接就实例化SerializeConfig就会出现实例化失败的异常。为了方便重现直接用简单的main方法:
import com.alibaba.fastjson.serializer.SerializeConfig;
public class AppTest
public static void main(String[] args){
new SerializeConfig();
}
}
该问题在当前的最新版本1.2.74仍然存在。