我有一个项目,希望将版本从Java 1.7更新为Java 1.8,但是运行UnitTests时所有映射器测试均失败。
该项目正在使用:
SpringJUnit4ClassRunner
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.4.5</version>
</dependency>
对于那部分例外:nested exception is ma.glasnost.orika.MappingException: java.lang.RuntimeException: java.io.IOException: invalid constant type: 15 at 142
我发现了这个SO帖子:Reflections - Java 8 - invalid constant type
但是我不确定这是否真的是问题,因为我不依赖于“javassist”。
这是否与同一个问题有关?
我该如何克服?
更完整的StackTrace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.company.APP.common.mapping.orika.configuration.mappers.user.UserMapperTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected ma.glasnost.orika.MapperFacade com.company.APP.common.mapping.orika.configuration.mappers.BaseMapperTest.mapper; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mapperFacadeFactoryBean': FactoryBean threw exception on object creation; nested exception is ma.glasnost.orika.MappingException: java.lang.RuntimeException: java.io.IOException: invalid constant type: 15 at 142
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:385)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:82)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:199)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:251)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:253)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:216)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:82)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:60)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:67)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:162)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected ma.glasnost.orika.MapperFacade com.company.APP.common.mapping.orika.configuration.mappers.BaseMapperTest.mapper; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mapperFacadeFactoryBean': FactoryBean threw exception on object creation; nested exception is ma.glasnost.orika.MappingException: java.lang.RuntimeException: java.io.IOException: invalid constant type: 15 at 142
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:555)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 25 more
...
...
...
Caused by: java.io.IOException: invalid constant type: 15 at 142
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1044)
at javassist.bytecode.ConstPool.read(ConstPool.java:984)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:125)
at javassist.bytecode.ClassFile.read(ClassFile.java:770)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:114)
at javassist.CtClassType.getClassFile2(CtClassType.java:191)
... 79 more
最佳答案
您的想法朝着正确的方向发展。java.lang.RuntimeException: java.io.IOException: invalid constant type: 15 at 142
显示应用程序存在Java 8问题-如您的链接所述。
如您在堆栈跟踪中所见,ma.glasnost.orika映射器取决于javassist。
这是orika的传递依赖。
您可以使用mvn dependency:tree -verbose
构建依赖关系树。
在这里,您可以查找依赖于Javassist的库以及确切的版本。
要使用兼容Java 8的javassist版本,请使用该依赖关系来覆盖orika的隐式依赖关系:
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
</dependency>
但是对于此示例,最好将orika版本升级到1.4.6,因为该版本已支持Java 8。