Apache HTTP客户端和日志记录的问题

编程入门 行业动态 更新时间:2024-10-28 06:26:57
本文介绍了Apache HTTP客户端和日志记录的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的Tapestry应用程序中,我有时需要对某个URL进行GET请求.我这样做(使用Apache的HttpClient 4.2.1)

In my Tapestry application, I need to do a GET request to a certain URL at some point. I do it like this (using Apache's HttpClient 4.2.1)

String scheme = getScheme(); String host = getHost(); int port = getPort(); String path = getPath(); String paramKey = getParamKey(); String paramValue = getParamValue(); URIBuilder builder = new URIBuilder(); builder .setScheme(scheme) .setHost(host) .setPort(port) .setPath(path) .setParameter(paramKey, paramValue); URI uri = builder.build(); HttpGet getRequest = new HttpGet(uri); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(getRequest);

当我在Glassfish(3.1.2.2)上部署WAR并执行有问题的代码时,会引发以下异常:

When I deploy my WAR on Glassfish (3.1.2.2) and the code in question is executed, the following exception is thrown:

Caused by: org.apachemons.logging.LogConfigurationException: org.apachemons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@78aded17 for org.apachemons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category) (Caused by org.apachemons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@78aded17 for org.apachemons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category)) at org.apachemons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543) at org.apachemons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235) at org.apachemons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209) at org.apachemons.logging.LogFactory.getLog(LogFactory.java:351) at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:187) at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:146)

我在pom.xml中指定了此

I specify this in my pom.xml

<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.2.1</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency>

然后我检查并确保未找到"的类实际上在WEB-INF/lib/log4j-1.2.14中.

And I checked and made sure the Class that is "not being found" is actually in WEB-INF/lib/log4j-1.2.14.

有什么办法解决这个问题?

Is there any way to solve this issue?

推荐答案

您遇到了类加载器问题.也许首先加载使用不同log4j版本的另一个Web应用程序.类加载器使用找到的类的第一个版本. 试试这个:

You have a classloader problem. Maybe another web application, that uses different log4j version, is loaded first. The classloader uses the first version of the class it finds. Try this:

  • 从应用程序服务器中删除所有其他应用程序
  • 检查服务器的类路径中是否没有其他log4j.

尝试安装并启动您的应用程序.

Try to install and start your application.

更多推荐

Apache HTTP客户端和日志记录的问题

本文发布于:2023-11-24 11:30:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625023.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   日志   Apache   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!