即使我没有使用 Base64,也会发生这种情况。
我确实在 Glassfish 中的域的 lib 目录中引用了 commons-codec-1.9,并且在 httpclient-4.3.4 和 lib 目录中也引用了导致错误的代码。
try {
Authenticator.setDefault(new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("myusername", "mypassword".toCharArray());
}
});
String xmlRequestString = formatXMLRequest((Exception) exception);
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost("http://mysite.org/post.xml");
StringEntity entity = new StringEntity(xmlRequestString);
entity.setContentType("text/xml");
post.setEntity(entity);
client.execute(post); // <--- HERE is where the error is thrown
} catch (Exception ex) {
Logger.getLogger(LogManagerBean.class.getName()).log(Level.SEVERE, null, ex);
}
有什么想法吗?
最佳答案
这是一个二进制兼容性问题,是由于 Web 应用程序的有效类路径中的库不兼容而导致的。具体来说,包含 BasicScheme
类的 JAR 文件与包含 Base64
类的 JAR 文件不兼容。前者包含对类加载器找到的后者版本中不存在的方法的调用。
This is occurring even though I'm not using Base64.
是的。但是 BasicScheme
类 >> 是<<,并且有东西使用该类。
签名org.apache.commons.codec.binary.Base64.(I)V
指的是采用int
参数的构造函数。根据 GrepCode 的说法,自 1.4 版以来的所有版本的 Apache Commons Codec 都有这个构造函数。但1.3版本没有。因此,请在您的应用程序服务器中查找“commons-codec”JAR 文件的旧副本。
请注意,如果 Web 应用(或其他应用程序)的类路径中有多个版本的库,则类路径中较早的 JAR 文件中的版本获胜。
关于java - NoSuchMethodError : org. apache.commons.codec.binary.Base64.(I)V 在 org.apache.http.impl.auth.BasicScheme.(BasicScheme.java:65),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24835796/