创建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

任何帮助!

最佳答案

显然看起来像下面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

关于java - 创建Abdera客户端失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21904319/

10-12 04:25