Java教程

【Spring】使用SpringTest报错 java.lang.NoSuchMethodError

本文主要是介绍【Spring】使用SpringTest报错 java.lang.NoSuchMethodError,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

完整报错信息:

"C:\Program Files\Java\jdk1.8.0_301\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\lib\idea_rt.jar=53174:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\plugins\junit\lib\junit-rt.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\rt.jar;C:\Users\Cloud9\IdeaProjects\EveryThing-Framework\target\test-classes;C:\Users\Cloud9\IdeaProjects\EveryThing-Framework\target\classes;D:\Maven Local Repository\org\apache\curator\curator-framework\5.2.0\curator-framework-5.2.0.jar;D:\Maven Local Repository\org\apache\curator\curator-client\5.2.0\curator-client-5.2.0.jar;D:\Maven Local Repository\org\apache\zookeeper\zookeeper\3.6.3\zookeeper-3.6.3.jar;D:\Maven Local Repository\org\apache\zookeeper\zookeeper-jute\3.6.3\zookeeper-jute-3.6.3.jar;D:\Maven Local Repository\org\apache\yetus\audience-annotations\0.5.0\audience-annotations-0.5.0.jar;D:\Maven Local Repository\io\netty\netty-handler\4.1.63.Final\netty-handler-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-common\4.1.63.Final\netty-common-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-resolver\4.1.63.Final\netty-resolver-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-buffer\4.1.63.Final\netty-buffer-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-transport\4.1.63.Final\netty-transport-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-codec\4.1.63.Final\netty-codec-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-transport-native-epoll\4.1.63.Final\netty-transport-native-epoll-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-transport-native-unix-common\4.1.63.Final\netty-transport-native-unix-common-4.1.63.Final.jar;D:\Maven Local Repository\org\apache\curator\curator-recipes\5.2.0\curator-recipes-5.2.0.jar;D:\Maven Local Repository\commons-io\commons-io\2.11.0\commons-io-2.11.0.jar;D:\Maven Local Repository\commons-beanutils\commons-beanutils\1.7.0\commons-beanutils-1.7.0.jar;D:\Maven Local Repository\commons-logging\commons-logging\1.0.3\commons-logging-1.0.3.jar;D:\Maven Local Repository\org\javassist\javassist\3.26.0-GA\javassist-3.26.0-GA.jar;D:\Maven Local Repository\com\alibaba\fastjson\1.2.78\fastjson-1.2.78.jar;D:\Maven Local Repository\javax\servlet\javax.servlet-api\4.0.1\javax.servlet-api-4.0.1.jar;D:\Maven Local Repository\javax\servlet\jstl\1.2\jstl-1.2.jar;D:\Maven Local Repository\javax\servlet\jsp\javax.servlet.jsp-api\2.3.3\javax.servlet.jsp-api-2.3.3.jar;D:\Maven Local Repository\org\reflections\reflections\0.9.11\reflections-0.9.11.jar;D:\Maven Local Repository\com\google\guava\guava\20.0\guava-20.0.jar;D:\Maven Local Repository\mysql\mysql-connector-java\8.0.25\mysql-connector-java-8.0.25.jar;D:\Maven Local Repository\com\google\protobuf\protobuf-java\3.11.4\protobuf-java-3.11.4.jar;D:\Maven Local Repository\io\jsonwebtoken\jjwt\0.9.1\jjwt-0.9.1.jar;D:\Maven Local Repository\com\fasterxml\jackson\core\jackson-databind\2.9.6\jackson-databind-2.9.6.jar;D:\Maven Local Repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;D:\Maven Local Repository\com\fasterxml\jackson\core\jackson-core\2.9.6\jackson-core-2.9.6.jar;D:\Maven Local Repository\org\apache\httpcomponents\httpclient\4.5.13\httpclient-4.5.13.jar;D:\Maven Local Repository\org\apache\httpcomponents\httpcore\4.4.13\httpcore-4.4.13.jar;D:\Maven Local Repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;D:\Maven Local Repository\org\apache\httpcomponents\httpmime\4.5.13\httpmime-4.5.13.jar;D:\Maven Local Repository\junit\junit\4.12\junit-4.12.jar;D:\Maven Local Repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\Maven Local Repository\org\slf4j\slf4j-api\1.7.32\slf4j-api-1.7.32.jar;D:\Maven Local Repository\org\slf4j\slf4j-log4j12\1.7.32\slf4j-log4j12-1.7.32.jar;D:\Maven Local Repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;D:\Maven Local Repository\cglib\cglib\2.2.2\cglib-2.2.2.jar;D:\Maven Local Repository\asm\asm\3.3.1\asm-3.3.1.jar;D:\Maven Local Repository\org\apache\poi\poi\5.0.0\poi-5.0.0.jar;D:\Maven Local Repository\org\slf4j\jcl-over-slf4j\1.7.30\jcl-over-slf4j-1.7.30.jar;D:\Maven Local Repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;D:\Maven Local Repository\org\apache\commons\commons-math3\3.6.1\commons-math3-3.6.1.jar;D:\Maven Local Repository\com\zaxxer\SparseBitSet\1.2\SparseBitSet-1.2.jar;D:\Maven Local Repository\org\apache\poi\poi-ooxml\5.0.0\poi-ooxml-5.0.0.jar;D:\Maven Local Repository\org\apache\poi\poi-ooxml-lite\5.0.0\poi-ooxml-lite-5.0.0.jar;D:\Maven Local Repository\org\apache\xmlbeans\xmlbeans\4.0.0\xmlbeans-4.0.0.jar;D:\Maven Local Repository\org\apache\commons\commons-compress\1.20\commons-compress-1.20.jar;D:\Maven Local Repository\com\github\virtuald\curvesapi\1.06\curvesapi-1.06.jar;D:\Maven Local Repository\org\bouncycastle\bcpkix-jdk15on\1.68\bcpkix-jdk15on-1.68.jar;D:\Maven Local Repository\org\bouncycastle\bcprov-jdk15on\1.68\bcprov-jdk15on-1.68.jar;D:\Maven Local Repository\org\apache\santuario\xmlsec\2.2.1\xmlsec-2.2.1.jar;D:\Maven Local Repository\com\fasterxml\woodstox\woodstox-core\5.2.1\woodstox-core-5.2.1.jar;D:\Maven Local Repository\org\codehaus\woodstox\stax2-api\4.2\stax2-api-4.2.jar;D:\Maven Local Repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.2\jakarta.xml.bind-api-2.3.2.jar;D:\Maven Local Repository\jakarta\activation\jakarta.activation-api\1.2.1\jakarta.activation-api-1.2.1.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-all\1.13\batik-all-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-anim\1.13\batik-anim-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-shared-resources\1.13\batik-shared-resources-1.13.jar;D:\Maven Local Repository\xml-apis\xml-apis-ext\1.3.04\xml-apis-ext-1.3.04.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-awt-util\1.13\batik-awt-util-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\xmlgraphics-commons\2.4\xmlgraphics-commons-2.4.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-bridge\1.13\batik-bridge-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-codec\1.13\batik-codec-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-constants\1.13\batik-constants-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-css\1.13\batik-css-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-dom\1.13\batik-dom-1.13.jar;D:\Maven Local Repository\xalan\xalan\2.7.2\xalan-2.7.2.jar;D:\Maven Local Repository\xalan\serializer\2.7.2\serializer-2.7.2.jar;D:\Maven Local Repository\xml-apis\xml-apis\1.4.01\xml-apis-1.4.01.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-ext\1.13\batik-ext-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-extension\1.13\batik-extension-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-gui-util\1.13\batik-gui-util-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-gvt\1.13\batik-gvt-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-i18n\1.13\batik-i18n-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-parser\1.13\batik-parser-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-rasterizer-ext\1.13\batik-rasterizer-ext-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-rasterizer\1.13\batik-rasterizer-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-script\1.13\batik-script-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-slideshow\1.13\batik-slideshow-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-squiggle-ext\1.13\batik-squiggle-ext-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-squiggle\1.13\batik-squiggle-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-svg-dom\1.13\batik-svg-dom-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-svgbrowser\1.13\batik-svgbrowser-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-svggen\1.13\batik-svggen-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-svgpp\1.13\batik-svgpp-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-svgrasterizer\1.13\batik-svgrasterizer-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-swing\1.13\batik-swing-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-transcoder\1.13\batik-transcoder-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-util\1.13\batik-util-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-ttf2svg\1.13\batik-ttf2svg-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-xml\1.13\batik-xml-1.13.jar;D:\Maven Local Repository\de\rototor\pdfbox\graphics2d\0.30\graphics2d-0.30.jar;D:\Maven Local Repository\org\apache\pdfbox\pdfbox\2.0.22\pdfbox-2.0.22.jar;D:\Maven Local Repository\org\apache\pdfbox\fontbox\2.0.22\fontbox-2.0.22.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch\7.15.1\elasticsearch-7.15.1.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-core\7.15.1\elasticsearch-core-7.15.1.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-secure-sm\7.15.1\elasticsearch-secure-sm-7.15.1.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-x-content\7.15.1\elasticsearch-x-content-7.15.1.jar;D:\Maven Local Repository\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;D:\Maven Local Repository\com\fasterxml\jackson\dataformat\jackson-dataformat-smile\2.10.4\jackson-dataformat-smile-2.10.4.jar;D:\Maven Local Repository\com\fasterxml\jackson\dataformat\jackson-dataformat-yaml\2.10.4\jackson-dataformat-yaml-2.10.4.jar;D:\Maven Local Repository\com\fasterxml\jackson\dataformat\jackson-dataformat-cbor\2.10.4\jackson-dataformat-cbor-2.10.4.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-geo\7.15.1\elasticsearch-geo-7.15.1.jar;D:\Maven Local Repository\org\apache\lucene\lucene-core\8.9.0\lucene-core-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-analyzers-common\8.9.0\lucene-analyzers-common-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-backward-codecs\8.9.0\lucene-backward-codecs-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-grouping\8.9.0\lucene-grouping-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-highlighter\8.9.0\lucene-highlighter-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-join\8.9.0\lucene-join-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-memory\8.9.0\lucene-memory-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-misc\8.9.0\lucene-misc-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-queries\8.9.0\lucene-queries-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-queryparser\8.9.0\lucene-queryparser-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-sandbox\8.9.0\lucene-sandbox-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-spatial-extras\8.9.0\lucene-spatial-extras-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-spatial3d\8.9.0\lucene-spatial3d-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-suggest\8.9.0\lucene-suggest-8.9.0.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-cli\7.15.1\elasticsearch-cli-7.15.1.jar;D:\Maven Local Repository\net\sf\jopt-simple\jopt-simple\5.0.2\jopt-simple-5.0.2.jar;D:\Maven Local Repository\com\carrotsearch\hppc\0.8.1\hppc-0.8.1.jar;D:\Maven Local Repository\org\lz4\lz4-java\1.8.0\lz4-java-1.8.0.jar;D:\Maven Local Repository\joda-time\joda-time\2.10.10\joda-time-2.10.10.jar;D:\Maven Local Repository\com\tdunning\t-digest\3.2\t-digest-3.2.jar;D:\Maven Local Repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;D:\Maven Local Repository\org\apache\logging\log4j\log4j-api\2.11.1\log4j-api-2.11.1.jar;D:\Maven Local Repository\org\elasticsearch\jna\5.7.0-1\jna-5.7.0-1.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-plugin-classloader\7.15.1\elasticsearch-plugin-classloader-7.15.1.jar;D:\Maven Local Repository\org\apache\activemq\activemq-all\5.16.3\activemq-all-5.16.3.jar;D:\Maven Local Repository\org\springframework\spring-core\5.2.18.RELEASE\spring-core-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-jcl\5.2.18.RELEASE\spring-jcl-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-web\5.2.18.RELEASE\spring-web-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-beans\5.2.18.RELEASE\spring-beans-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-oxm\5.2.18.RELEASE\spring-oxm-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-tx\5.2.18.RELEASE\spring-tx-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-jdbc\5.2.18.RELEASE\spring-jdbc-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-webmvc\5.2.18.RELEASE\spring-webmvc-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-context\5.2.18.RELEASE\spring-context-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-expression\5.2.18.RELEASE\spring-expression-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-aop\5.2.18.RELEASE\spring-aop-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-context-support\5.2.18.RELEASE\spring-context-support-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-test\5.2.18.RELEASE\spring-test-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-jms\5.2.18.RELEASE\spring-jms-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-messaging\5.2.18.RELEASE\spring-messaging-5.2.18.RELEASE.jar;D:\Maven Local Repository\javax\jms\javax.jms-api\2.0.1\javax.jms-api-2.0.1.jar;D:\Maven Local Repository\org\apache\xbean\xbean-spring\3.7\xbean-spring-3.7.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 cn.cloud9.test.activemq.springactivemq.SpringActiveMqConsumer,springActiveMqConsume
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/Maven%20Local%20Repository/org/slf4j/slf4j-log4j12/1.7.32/slf4j-log4j12-1.7.32.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/Maven%20Local%20Repository/org/apache/activemq/activemq-all/5.16.3/activemq-all-5.16.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
[2021-11-02 08:14:25 上午]:DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:139)SpringJUnit4ClassRunner constructor called with [class cn.cloud9.test.activemq.springactivemq.SpringActiveMqConsumer]
[2021-11-02 08:14:25 上午]:DEBUG org.springframework.test.context.BootstrapUtils.createCacheAwareContextLoaderDelegate(BootstrapUtils.java:96)Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
[2021-11-02 08:14:25 上午]:DEBUG org.springframework.test.context.BootstrapUtils.createBootstrapContext(BootstrapUtils.java:79)Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
[2021-11-02 08:14:25 上午]:DEBUG org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:132)Instantiating TestContextBootstrapper for test class [cn.cloud9.test.activemq.springactivemq.SpringActiveMqConsumer] from class [org.springframework.test.context.support.DefaultTestContextBootstrapper]

java.lang.NoSuchMethodError: org.springframework.util.Assert.notNull(Ljava/lang/Object;Ljava/util/function/Supplier;)V

    at org.springframework.test.context.support.ContextLoaderUtils.resolveContextConfigurationAttributes(ContextLoaderUtils.java:244)
    at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:295)
    at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:108)
    at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:137)
    at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:122)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:151)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:142)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)


Process finished with exit code -1

 

问题出现在使用SpringTest组件的注解 @Runwith上面

package cn.cloud9.test.activemq.springactivemq;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


@RunWith(SpringJUnit4ClassRunner.class) // junit与spring整合
@ContextConfiguration(locations = {"classpath:ActiveMQ-Consumer.xml"}) // 加载spring配置文件
public class SpringActiveMqConsumer {

    @Test
    public void springActiveMqConsume() throws Exception {
        // ApplicationContext ac = new ClassPathXmlApplicationContext("ActiveMQ-Consumer.xml");
        System.in.read();
    }
}

 

 

所有Spring组件配置版本:

<spring-version>5.2.18.RELEASE</spring-version>

Junit测试版本:

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

 

解决办法是给SpringTest单独设置版本:

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <!--<version>${spring-version}</version>-->
            <version>4.1.6.RELEASE</version>
        </dependency>

参考博客:

https://blog.csdn.net/wuzongpo/article/details/52036096

 

问题原因尚未找到。。。。

 

这篇关于【Spring】使用SpringTest报错 java.lang.NoSuchMethodError的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!