java.lang.NoSuchMethodError: org.springframework.http.MediaType.getCharset()Ljava/nio/charset/Charset
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38442676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.NoSuchMethodError: org.springframework.http.MediaType.getCharset()Ljava/nio/charset/Charset
提问by Zack Macomber
When I attempt to run my TestNG
tests via ant
I am getting java.lang.NoSuchMethodError: org.springframework.http.MediaType.getCharset()Ljava/nio/charset/Charset
(see below for full exception)
当我尝试运行我的TestNG
测试时,ant
我得到了java.lang.NoSuchMethodError: org.springframework.http.MediaType.getCharset()Ljava/nio/charset/Charset
(完整的例外见下文)
I have no trouble compiling or running my web application but can't run tests via ant. I'm fairly certain this is a class loading issue but not sure what order class loading should be done at runtime. I'm using Spring 4.3.1 and Spring Security 4.1.1.
我编译或运行我的 Web 应用程序没有问题,但无法通过 ant 运行测试。我相当确定这是一个类加载问题,但不确定在运行时应该按什么顺序加载类。我正在使用 Spring 4.3.1 和 Spring Security 4.1.1。
Is there a particular order to load my jars such that the "correct" version of org.springframework.http.MediaType
is used?
是否有特定的顺序来加载我的罐子,以便使用“正确”的版本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.
采纳答案by Zack Macomber
Unbelievable...foiled by class loading issues once again...an uber jar named activemq-minimal-5.13.3.jar
had references to spring
jars in it that was causing the conflict. activemq-minimal-5.13.3.jar
comes before spring
alphabetically so the classes in that activemq
jar were being loaded/used over the spring
jars. Updated my ant build to load the spring
classes first and now I'm all set.
令人难以置信……再次被类加载问题所困扰……一个名为 uber jar 的 jaractivemq-minimal-5.13.3.jar
引用了spring
导致冲突的 jar。 activemq-minimal-5.13.3.jar
来之前spring
按字母顺序,以便在这些类activemq
广口瓶中被装载/过所使用的spring
广口瓶中。更新了我的 ant 构建以spring
首先加载类,现在我已经准备好了。
The way I found out is I put all of my 3rd party libs together in a "Test" project and added/deleted jars (with somewhat of an inclination where the problem was) until I was able to pinpoint where the class loading issue was.
我发现的方法是我将所有 3rd 方库放在一个“测试”项目中并添加/删除罐子(有点倾向于问题所在),直到我能够查明类加载问题的位置。
回答by Issam EL-ATIF
org.springframework.http.MediaType.getCharset()
was introduced since 4.3 if java did not find it that mean that you have a spring-core version below 4.3.1 in your classpath which get loaded and used.
org.springframework.http.MediaType.getCharset()
从 4.3 开始引入,如果 java 没有找到它,这意味着你的类路径中有一个低于 4.3.1 的 spring-core 版本,它被加载和使用。
回答by vaquar khan
In spring latest version they have modified
在春季最新版本中,他们已修改
org.springframework.http;
org.springframework.http;
MediaType contentType = headers.getContentType();
Old :
老的 :
contentType.getCharSet()
New :
新的 :
contentType.getCharset()