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
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:
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.
We had a similar issue when we are migrating to Spring 4.1.1
In our case, we had a dependency as follows
<dependency>
<groupId>org.springframework.javaconfig</groupId>
<artifactId>spring-javaconfig</artifactId>
<version>1.0.0.m3</version>
</dependency>
We added this dependency inorder to support Post Processing of a bean
<bean class="org.springframework.config.java.process.ConfigurationPostProcessor" />
There is a class from the above dependency "ProcessUtils.java", Which is invoking ClassUtils.forName with a Single argument (String). However this method has been deprecated. So the Exeception is being thrown.
I have learnt from another post in stackoverflow that we do not need a ConfigurationPostProcessor with Spring 4.1.1 (am not sure of exact version, when this support is enabled)
Once we removed the following from our Configuration (Spring Context file), the problem is resolved.
You may have already figured this out but still in my case i was using a spring-orm whose version was different from spring-core and thus was getting similar error message when running unit tests. I have learnt from my experience that all the spring jar files included in a project should have the same version to avoid unnecessary issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With