解决启动时报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.(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.(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.(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(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即可。

...

	   
            org.apache.httpcomponents
            httpclient
            4.5.3
        
...

sample-txc-dubbo工程也有一样的问题,依次修改即可。

你可能感兴趣的:(分布式事务)