创建apache Abdera客户端失败
我的部分代码是
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
这让我失望......
java.lang.RuntimeException: java.lang.NoSuchMethodException: org.apache.abdera.protocol.client.cache.LRUCacheFactory.<init>(org.apache.abdera.Abdera)
at org.apache.abdera.util.Discover.locate(Discover.java:37)
at org.apache.abdera.util.Discover.locate(Discover.java:21)
at org.apache.abdera.util.ServiceUtil.newInstance(ServiceUtil.java:142)
at org.apache.abdera.protocol.client.AbderaClient.initCacheFactory(AbderaClient.java:132)
at org.apache.abdera.protocol.client.AbderaClient.<init>(AbderaClient.java:108)
at org.apache.abdera.protocol.client.AbderaClient.<init>(AbderaClient.java:9
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
Caused by: java.lang.NoSuchMethodException: org.apache.abdera.protocol.client.cache.LRUCacheFactory.<init>(org.apache.abdera.Abdera)
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getConstructor(Class.java:1657)
at org.apache.abdera.util.Discover.load(Discover.java:149)
at org.apache.abdera.util.Discover.locate(Discover.java:33)
... 30 more
任何帮助!!
答案 0 :(得分:2)
显然看起来像AbderaClient
的以下方法中的错误;它使用反射来定位LRUCacheFactory的构造函数:
private CacheFactory initCacheFactory() {
CacheFactory cacheFactory =
(CacheFactory)Discover.locate(
CacheFactory.class.getName(),
LRUCacheFactory.class.getName(),
abdera);
return cacheFactory;
}
检查您的LRUCacheFactory
版本中是否有任何此类构造函数。
建议切换到最新的Abdera版本(1.1.3)。但是,我在论坛中找到了解决方法。试试它是否有效。
AbderaClient client;
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
ClassLoader cl = this.getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(cl);
Abdera abdera = new Abdera();
client = new AbderaClient(abdera);
// Do something with client
} finally {
// Restore original classloader
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
有关此解决方法的详细信息,请参阅this link。