运行测试抛出NoSuchMethodError

问题描述 投票:0回答:1

我最近从 Java 8 和 10.0.0.Final 升级到 Java 11 和 Widfly 15.0.0.Final。但由于某种原因,测试脚本失败并出现以下异常。我已将weld和cdi升级到更高版本。

这里是例外:

java.lang.NoSuchMethodError: 'int javax.enterprise.inject.spi.ObserverMethod.getPriority()'

at org.jboss.weld.resolution.TypeSafeObserverResolver$ObserverMethodComparator.compare(TypeSafeObserverResolver.java:55)
at org.jboss.weld.resolution.TypeSafeObserverResolver$ObserverMethodComparator.compare(TypeSafeObserverResolver.java:46)
at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.base/java.util.TimSort.sort(TimSort.java:220)
at java.base/java.util.Arrays.sort(Arrays.java:1515)
at java.base/java.util.ArrayList.sort(ArrayList.java:1750)
at java.base/java.util.Collections.sort(Collections.java:179)
at org.jboss.weld.resolution.TypeSafeObserverResolver.sortResult(TypeSafeObserverResolver.java:106)
at org.jboss.weld.resolution.TypeSafeObserverResolver.sortResult(TypeSafeObserverResolver.java:44)
at org.jboss.weld.resolution.TypeSafeResolver$ResolvableToBeanCollection.apply(TypeSafeResolver.java:52)
at org.jboss.weld.resolution.TypeSafeResolver$ResolvableToBeanCollection.apply(TypeSafeResolver.java:43)
at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.lambda$null$0(ReentrantMapBackedComputingCache.java:55)
at org.jboss.weld.util.LazyValueHolder$1.computeValue(LazyValueHolder.java:32)
at org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:46)
at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getValue(ReentrantMapBackedComputingCache.java:72)
at org.jboss.weld.resolution.TypeSafeResolver.resolve(TypeSafeResolver.java:88)
at org.jboss.weld.event.ObserverNotifier.resolveObserverMethods(ObserverNotifier.java:147)
at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:177)
at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:171)
at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:53)
at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:44)
at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:54)
at org.jboss.weld.bootstrap.WeldStartup.startInitialization(WeldStartup.java:407)
at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:79)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:802)
at org.jglue.cdiunit.CdiRunner.createTest(CdiRunner.java:129)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)

这是 pom:

    <dependency>
        <groupId>jakarta.enterprise</groupId>
        <artifactId>jakarta.enterprise.cdi-api</artifactId>
        <version>2.0.2</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.weld.se</groupId>
        <artifactId>weld-se-shaded</artifactId>
        <version>3.1.0.Final</version>
        <scope>test</scope>
    </dependency>
    <!-- cdi-unit should be after javaee -->
    <dependency>
        <groupId>org.jglue.cdi-unit</groupId>
        <artifactId>cdi-unit</artifactId>
        <version>4.1.0</version>
        <scope>test</scope>
    </dependency>

我现在不知道什么地方可能出了问题。

maven java-11 java-ee-8 wildfly-15
1个回答
0
投票

CDI Unit 4.x 与 Jakarta API 规范不兼容。

请使用最新的5.0.0 EA3早期访问版本

© www.soinside.com 2019 - 2024. All rights reserved.