gpt4 book ai didi

java.lang.NoSuchMethodError : org. springframework.http.MediaType.getCharset()Ljava/nio/charset/Charset 错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:17:07 29 4
gpt4 key购买 nike

当我尝试通过 ant 运行我的 TestNG 测试时,我得到了 java.lang.NoSuchMethodError: org.springframework.http.MediaType.getCharset() Ljava/nio/charset/Charset(完整异常(exception)见下文)

我可以轻松编译或运行我的 Web 应用程序,但无法通过 ant 运行测试。我相当确定这是一个类加载问题,但不确定在运行时应该按什么顺序加载类。我正在使用 Spring 4.3.1 和 Spring Security 4.1.1。

加载我的 jar 是否有特定的顺序,以便使用“正确”版本的 org.springframework.http.MediaType

[testng] org.testng.TestNGException: 
[testng] An error occurred while instantiating class com.avada.rest.api.GroupsIntTest: org.springframework.http.MediaType.getCharset()Ljava/nio/charset/Charset;
[testng] at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:388)
[testng] at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:290)
[testng] at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:125)
[testng] at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:191)
[testng] at org.testng.TestClass.getInstances(TestClass.java:104)
[testng] at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:90)
[testng] at org.testng.TestClass.init(TestClass.java:82)
[testng] at org.testng.TestClass.<init>(TestClass.java:45)
[testng] at org.testng.TestRunner.initMethods(TestRunner.java:409)
[testng] at org.testng.TestRunner.init(TestRunner.java:247)
[testng] at org.testng.TestRunner.init(TestRunner.java:217)
[testng] at org.testng.TestRunner.<init>(TestRunner.java:161)
[testng] at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:555)
[testng] at org.testng.SuiteRunner.init(SuiteRunner.java:168)
[testng] at org.testng.SuiteRunner.<init>(SuiteRunner.java:117)
[testng] at org.testng.TestNG.createSuiteRunner(TestNG.java:1359)
[testng] at org.testng.TestNG.createSuiteRunners(TestNG.java:1346)
[testng] at org.testng.TestNG.runSuitesLocally(TestNG.java:1200)
[testng] at org.testng.TestNG.runSuites(TestNG.java:1124)
[testng] at org.testng.TestNG.run(TestNG.java:1096)
[testng] at org.testng.TestNG.privateMain(TestNG.java:1425)
[testng] at org.testng.TestNG.main(TestNG.java:1394)
[testng] Caused by: java.lang.NoSuchMethodError: org.springframework.http.MediaType.getCharset()Ljava/nio/charset/Charset;
[testng] at org.springframework.web.client.RestTemplate$AcceptHeaderRequestCallback.getSupportedMediaTypes(RestTemplate.java:757)
[testng] at org.springframework.web.client.RestTemplate$AcceptHeaderRequestCallback.doWithRequest(RestTemplate.java:733)
[testng] at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:617)
[testng] at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:580)
[testng] at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:287)
[testng] at com.avada.rest.api.ApiTestClient.getAll(ApiTestClient.java:81)
[testng] at com.avada.rest.api.GroupsIntTest.<clinit>(GroupsIntTest.java:17)
[testng] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[testng] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
[testng] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[testng] at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
[testng] at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
[testng] at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:377)
[testng] ... 21 more
[testng] The tests failed.

最佳答案

令人难以置信...再次被类加载问题挫败...一个名为 activemq-minimal-5.13.3.jar 的 uber jar 引用了 spring jar是它引起了冲突。 activemq-minimal-5.13.3.jar 按字母顺序排在 spring 之前,因此 activemq jar 中的类在 上加载/使用>spring jar 。更新我的 ant build 以首先加载 spring 类,现在我已经准备好了。

我发现的方法是将我所有的第 3 方库放在一个“测试”项目中,并添加/删除 jar(在问题所在的地方有一定的倾向),直到我能够查明类加载的位置问题是。

关于java.lang.NoSuchMethodError : org. springframework.http.MediaType.getCharset()Ljava/nio/charset/Charset 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38442676/

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