java - JCabi方面@RetryOnFailure如何抛出异常

标签 java aop jcabi

我想使用 JCabi 手动调用方法重试。面向方面的编程应该使这很容易,但我想不通。

import com.jcabi.aspects.RetryOnFailure;

public class Example
{

    public int j;

    @RetryOnFailure(attempts = 4, delay = 100, verbose = true)
    public void retryFun() throws Exception
    {
        j++;
        if(j<3)
            throw new Exception();
        else
            return;
    }

    public static void main(String[] args) throws Exception
    {
        Example example = new Example();
        System.out.println(example.j);
        example.retryFun();
        System.out.println(example.j);
    }
}

jcabi 中唯一可用的示例是下面的示例,它没有显示如何抛出异常以强制重试调用:

Annotate your methods with @RetryOnFailure annotation and in case of exception in the method its execution will be repeated a few times:

public class Resource {
  @RetryOnFailure(attempts = 2, delay = 10, verbose = false)
  public String load(URL url) {
    return url.openConnection().getContent();
  }
}

In an exception occurs the method will retry two times, with a 10 msec delay between attempts.

最佳答案

对于那些仍在寻找答案的人来说,叶戈尔的答案现在已经过时了。他发布的 jcabi-maven-plugin 版本 0.8 对我不起作用。

经过几个小时的挖掘,我找到了 this其中声明我们应该使用的最新版本 As of this time, July 20140.9.2

这就是我为什么在运行 mvn jcabi:ajc 时从链接中收到错误并且编织不工作的原因。

关于java - JCabi方面@RetryOnFailure如何抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18896204/

相关文章:

java - Java 中是否有相当于 Android 的 LRUCache 的东西?

javascript - ExtJS AOP 类似于dojo 中提供的吗?

c# - 使用 PostSharp 进行正确的单元测试

c# - 如何在来自单独应用程序的 c# 方法调用中注入(inject)代码

java - HttpURLConnection PUT 到 Google Cloud Storage 给出错误 403

java - 如何使用java创建这个JSONObject?

java - 如何通过某些属性将 List<Object> 分组到另一个 List<Object>

java - 如何使用 Java ssh JSch 和 jcabi-ssh 将密码传递给 scp

java - 无法使用 jcabi 父 pom 进行构建

android - 如何在android中使用jcabi-aspects Loggable注释?