gpt4 book ai didi

java - 升级到 Java 8 导致单元测试中的 Orika 映射器 java.io.IOException : invalid constant type: 15 at 142

转载 作者:行者123 更新时间:2023-11-30 12:08:02 25 4
gpt4 key购买 nike

我有一个项目,我想将版本从 Java 1.7 更新到 Java 1.8,但是运行单元测试时所有映射器测试都失败了。

该项目正在使用:SpringJUnit4ClassRunner

<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.4.5</version>
</dependency>

对于那部分异常:嵌套异常是 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,如您在 Stack Trace 中所见。这是 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。

关于java - 升级到 Java 8 导致单元测试中的 Orika 映射器 java.io.IOException : invalid constant type: 15 at 142,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54514612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com