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

When I tried to run my TestNG test through ant, I got Java lang.NoSuchMethodError:org. springframework. http. MediaType. Getcharset() ljava / NiO / charset / charset (see complete exception below)

I have no problem compiling or running my web application, but I can't run the test through ant I'm sure it's a class loading problem, but I'm not sure what classes should be loaded at run time I am using spring 4.3 1 and spring security 4.1 one

Is there a specific order to load my cans so that I can use org springframework. http. "Correct" version of 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.

Solution

Unbelievable... Frustrated by the class loading problem again... One called activemq-minimal-5.13 The super jar of 3. Jar refers to the spring jar that caused the conflict activemq-minimal-5.13. 3. Jar is listed alphabetically before spring, so the classes in ActiveMQ jar are being loaded / used on spring jar I updated my ant build to load the spring class first, and now I've finished setting it up

The method I found is to put all my third-party libraries in a "test" project and add / remove cans (a little inclined to the problem) until I can determine the location of the class loading problem

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>