xml java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22465906/
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.util.ClassUtils.forName(Ljava
提问by Vladimir
I use very simple code that returns XML
我使用非常简单的代码返回 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
请帮忙。谢谢,弗拉基米尔
回答by JamesB
A NoSuchMethodError at runtime indicates that you are using a different version of a library than the version the code was built against.
运行时的 NoSuchMethodError 表示您使用的库版本与构建代码的版本不同。
In your case, Spring is the culprit. Check what is on the classpath at runtime and ensure the following:
在您的情况下,Spring 是罪魁祸首。在运行时检查类路径上的内容并确保以下内容:
- the version is the same as the compile time jar
- if there is more than one version, remove the one not required
- 版本与编译时jar相同
- 如果有多个版本,删除一个不需要的
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.
查看http://docs.spring.io/spring/docs/3.2.0.M1/api/org/springframework/util/ClassUtils.html,看起来 ClassUtils.forName(String) 从 Spring 3 开始已被弃用. 我的猜测是您已经针对具有此方法的版本构建了代码,但正在使用已删除该方法的版本运行它。
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.
ClassUtils 类包含在 spring-core jar 中,因此我将确保在编译和运行时使用该 jar 的相同版本。
回答by Anjaneya Reddy
We had a similar issue when we are migrating to Spring 4.1.1
我们在迁移到 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 的后处理
<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.
上述依赖项“ProcessUtils.java”中有一个类,它使用单个参数(字符串)调用 ClassUtils.forName。但是,此方法已被弃用。所以正在抛出异常。
I have learnt from another postin stackoverflow that we do not need a ConfigurationPostProcessor with Spring 4.1.1 (am not sure of exact version, when this support is enabled)
我从stackoverflow 的另一篇文章中了解到,我们不需要 Spring 4.1.1 的 ConfigurationPostProcessor(我不确定确切版本,当启用此支持时)
Once we removed the following from our Configuration (Spring Context file), the problem is resolved.
一旦我们从我们的配置(Spring 上下文文件)中删除了以下内容,问题就解决了。
回答by Neeraj
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.
您可能已经知道了这一点,但在我的情况下,我使用的是 spring-orm,其版本与 spring-core 不同,因此在运行单元测试时收到类似的错误消息。我从我的经验中了解到,一个项目中包含的所有 spring jar 文件都应该具有相同的版本,以避免出现不必要的问题。

