Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

xml - java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava

I use very simple code that returns XML

RestTemplate restTemplate = new RestTemplate();

Source oResponse = restTemplate.postForObject(url, entity, Source.class,
            vars);

XPathOperations xpathTemplate = new Jaxp13XPathTemplate();
String address = xpathTemplate.evaluateAsString("//status", oResponse);

However, I get the following error

java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava/lang/String;)Ljava/lang/Class;
at org.springframework.xml.JaxpVersion.<clinit>(JaxpVersion.java:51)
at org.springframework.xml.transform.TraxUtils.isStaxSource(TraxUtils.java:70)
at org.springframework.xml.xpath.Jaxp13XPathTemplate.evaluate(Jaxp13XPathTemplate.java:131)
at org.springframework.xml.xpath.Jaxp13XPathTemplate.evaluateAsString(Jaxp13XPathTemplate.java:91)

Please help. Thanks, Vladimir

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A NoSuchMethodError at runtime indicates that you are using a different version of a library than the version the code was built against.

In your case, Spring is the culprit. Check what is on the classpath at runtime and ensure the following:

  • the version is the same as the compile time jar
  • if there is more than one version, remove the one not required

Looking at http://docs.spring.io/spring/docs/3.2.0.M1/api/org/springframework/util/ClassUtils.html, it would appear that ClassUtils.forName(String) is deprecated as of Spring 3. My guess would be you have built your code against a version which had this method but are running it with a version where the method has been removed.

The ClassUtils class is contained within the spring-core jar so I would ensure the same version of this jar is used at both compile and run time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...