java – NoSuchMethodError:com.google.common.base.Stopwatch.createStarted()Lcom / google / common / base / Stopwatch

前端之家收集整理的这篇文章主要介绍了java – NoSuchMethodError:com.google.common.base.Stopwatch.createStarted()Lcom / google / common / base / Stopwatch前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用正在抛出NoSuchMethodError:com.google.common.base.Stopwatch.createStarted()Lcom / google / common / base / Stopwatch错误.不知道为什么,因为16.0.1确实包含那个类,我已经检查了.根据我的研究,看起来这是一个错误

我也有这个代码用于引用,但我认为这不是问题:

FirewallRule rule = new PeriodicFirewallCounterRule(60,TimeUnit.SECONDS,new IpAddressCountingPolicy());
    ((PeriodicFirewallCounterRule)rule).addHandler(new RateLimitationHandler(new UniqueLimitPolicy(10)));
    FirewallFilter firewallFiler = new FirewallFilter(getContext(),list(rule));
    firewallFiler.setNext(ma);

我的应用程序正在使用Restlet APISpark:

<dependency>
      <groupId>org.restlet.gae</groupId>
      <artifactId>org.restlet.ext.apispark</artifactId>
      <version>${version.restlet}</version>
  </dependency>

当运行并访问应用程序的REST API时,它会抛出此异常
错误

[INFO] Caused by: java.lang.NoSuchMethodError: com.google.common.base.Stopwatch.createStarted()Lcom/google/common/base/Stopwatch;
[INFO]  at org.restlet.ext.apispark.internal.firewall.rule.counter.PeriodicCounter.<init>(PeriodicCounter.java:65)
[INFO]  at org.restlet.ext.apispark.internal.firewall.rule.PeriodicFirewallCounterRule$1.load(PeriodicFirewallCounterRule.java:86)
[INFO]  at org.restlet.ext.apispark.internal.firewall.rule.PeriodicFirewallCounterRule$1.load(PeriodicFirewallCounterRule.java:84)
[INFO]  at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3599)
[INFO]  at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2379)
[INFO]  at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2342)
[INFO]  at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2257)
[INFO]  ... 74 more

解决方法

使用扩展名org.restlet.ext.apispark时,检索到的guava依赖项的版本为16.0.1.
Downloading: http://maven.restlet.com/com/google/guava/guava/16.0.1/guava-16.0.1.jar
Downloading: http://repo.maven.apache.org/maven2/com/google/guava/guava/16.0.1/guava-16.0.1.jar
Downloaded: http://repo.maven.apache.org/maven2/com/google/guava/guava/16.0.1/guava-16.0.1.jar (2176 KB at 711.7 KB/sec)

它位于从头开始创建的应用程序中,具有以下maven配置:

<project (...)>
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.restlet</groupId>
    <artifactId>restlet-apispark-firewall</artifactId>
    <name>${project.artifactId}</name>
    <packaging>jar</packaging>
    <version>1.0.0-snapshot</version>

    <properties>
        <java-version>1.7</java-version>
        <restlet-version>2.3.1</restlet-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.restlet.jse</groupId>
            <artifactId>org.restlet</artifactId>
            <version>${restlet-version}</version>
        </dependency>

        <dependency>
            <groupId>org.restlet.jse</groupId>
            <artifactId>org.restlet.ext.apispark</artifactId>
            <version>${restlet-version}</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>maven-restlet</id>
            <name>Public online Restlet repository</name>
            <url>http://maven.restlet.com</url>
        </repository>
    </repositories>
</project>

我整合了你的代码,它在我身边很好用.没有例外被抛出……

我认为Guava的旧版本来自另一个依赖.如果你使用Maven,你应该确定这个旧的番石榴版本来自哪里,并且可能在相应的依赖项中添加一个排除.我希望它能解决你的问题……

希望能帮助你,蒂埃里

原文链接:https://www.f2er.com/java/239828.html

猜你在找的Java相关文章