1

大家好,我正在尝试使用 StringUtils.remove 方法,但是下面的异常引发了我已经包含了 jar 文件和 StringUtils.lowercase 和 String.countsMatches 正在工作,只是删除不是可能的问题

<%@page import="org.apache.commons.lang.StringUtils"%>

这就是我导入的方式,异常如下

java.lang.NoSuchMethodError:
org.apache.commons.lang.StringUtils.remove(Ljava/lang/String;Ljava/lang/String;)
Ljava/lang/String;
4

2 回答 2

2

remove(String,String)方法已添加到 commons-lang 的 2.1 版中。它在 2.0 及更早版本中不存在。

根据您使用的 Servlet 容器或应用程序服务器(以及它的版本),服务器类路径可能包含过时版本的 commons-lang,它被用来代替应用程序 /lib 文件夹中的 commons-lang 副本。如果这是您的问题,您可以将应用程序配置为首选应用程序类路径,而不是服务器类路径。

于 2012-03-31T12:25:29.890 回答
0

因为据我在 javadoc StringUtils 中看到的,方法 remove 接受 2 个字符串参数,但没有接受 3 个参数的方法:

public static String remove(String str,
                            String remove)

http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/StringUtils.html

由于 StringUtils 有不同的版本,请仔细检查您在开发和部署环境中是否使用相同的版本。

于 2012-03-28T20:55:52.137 回答