spring beancopier Cannot invoke “Object.getClass()“ because “cause“ is null异常处理

我们项目用到spring beancopier, 在别的机器上运行正常,代码拉到我机器上就不正常了,抛出异常信息如题。

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.ibm.riskmeasure.rwaservice.service.singletest.impl.SingleTestServiceImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "cause" is null
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:217) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1315) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	... 51 common frames omitted
Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "cause" is null
	at org.springframework.cglib.core.CodeGenerationException.(CodeGenerationException.java:25) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:567) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:na]
	at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.cglib.beans.BeanCopier$Generator.create(BeanCopier.java:95) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.cglib.beans.BeanCopier.create(BeanCopier.java:51) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at com.ibm.riskmeasure.rwaservice.service.singletest.impl.SingleTestServiceImpl.(SingleTestServiceImpl.java:69) ~[classes/:na]
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[na:na]
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:204) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	... 53 common frames omitted

经研究发现,这个根源是java版本太新造成的,把我的环境换成java8就好了。当然,也可以升级spring-core到5.3x以上版本。

将Eclipse的jre库降级到JDK8

spring beancopier Cannot invoke “Object.getClass()“ because “cause“ is null异常处理_第1张图片

 

Eclipse中导入JDK类库的源代码以及添加指定的API

一、在Eclipse中导入JDK类库的源代码

操作步骤:
打开eclipse->“window”-> “Preferences” -> “Java” -> “Installed JRES”->选择你的JRE->”Edit”->”展开……xx\lib\rt.jar”->双击”Source Attachment:(none)”->”External location”->External File->选择你的JDK安装目录下的src.zip->ok、finish、apply and close->完成

使用:在 Java 编辑器中,选择类型、方法或字段的名称,按 F3 键转到定义(变量)或者查看源代码(类和方法)

注:
rt.jar包含了jdk的基础类库,也就是你在java doc里面看到的所有的类的class文件

或者,直接在相应的类或者方法上按F3,显示点击attach source,这里添加指定的压缩包路径即可

二、在Eclipse中添加指定的API

操作步骤:
打开eclipse->“window”-> “Preferences” -> “Java” -> “Installed JRES”->选择你的JRE->”Edit”->”展开……xx\lib\rt.jar”->双击”Javadoc location:”->”Javadoc URL-Javadoc location path:”->选择你的api位置->ok、finish、apply and close->完成

使用:在 Java 编辑器中,选择类型、方法的名称,按 Shift+F2 键查看api

注:
rt.jar包含了jdk的基础类库,也就是你在java doc里面看到的所有的类的class文件

转载于:https://www.cnblogs.com/ruber/p/10671079.html

你可能感兴趣的:(Java,spring,java,servlet)