解决启动时报ClassNotFoundException: org.apache.http.client.HttpClient异常的问题

最近在研究阿里的分布式事务框架GTS,在运行sample-txc-simple时,抛以下异常:

JM.Log:INFO Set diamond-client log path: C:\Users\chanson\logs\diamond-client
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient
    at com.taobao.txc.common.config.ConsoleConfig.g(Unknown Source)
    at com.taobao.txc.common.config.ConsoleConfig.<init>(Unknown Source)
    at com.taobao.txc.common.config.ConsoleConfig.a(Unknown Source)
    at com.taobao.txc.common.config.o.a(Unknown Source)
    at com.taobao.txc.common.config.o.a(Unknown Source)
    at com.taobao.txc.common.LoggerWrap.a(Unknown Source)
    at com.taobao.txc.common.config.o.a(Unknown Source)
    at com.taobao.txc.client.a.a(Unknown Source)
    at com.taobao.txc.client.a.<init>(Unknown Source)
    at com.taobao.txc.client.a.a(Unknown Source)
    at com.taobao.txc.client.aop.TxcTransactionScaner.a(Unknown Source)
    at com.taobao.txc.client.aop.TxcTransactionScaner.onApplicationEvent(Unknown Source)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:96)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:954)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.taobao.txc.test.Simple.main(Simple.java:39)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)

解决方案:

把pom.xml文件中的httpclient版本调高到4.5.3即可。

  <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.3</version>
        </dependency>

 

posted @ 2021-01-02 12:19  King-DA  阅读(3266)  评论(0编辑  收藏  举报