微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

当我尝试通过ant运行我的TestNG测试时,我得到java.lang.NoSuchMethodError:org.springframework.http.MediaType.getCharset()Ljava / nio / charset / Charset(请参阅下面的完整例外)

我编译或运行我的Web应用程序没有问题,但无法通过ant运行测试.我很确定这是一个类加载问题,但不确定应该在运行时加载什么类加载.我正在使用Spring 4.3.1和Spring Security 4.1.1.

是否有特定的顺序加载我的罐子,以便使用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.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.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的超级罐子引用了导致冲突的弹簧罐. activemq-minimal-5.13.3.jar按字母顺序排在spring之前,因此activemq jar中的类正在spring jar上加载/使用.更新了我的ant build以首先加载spring类,现在我已经完成了设置.

我发现的方法是将所有我的第三方库放在一个“测试”项目中并添加/删除罐子(有一点倾向于问题所在),直到我能够确定类加载问题的位置.

原文地址:https://www.jb51.cc/spring/432542.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐