我需要为一个项目进入 Apache 公共(public)链。所以我试图在以下位置运行一个基本示例:http://www.onjava.com/pub/a/onjava/2005/03/02/commonchains.html
Commons Chain 通过 Maven 安装。
我写了以下 Chain Base:
public class PFChain extends ChainBase {
public PFChain() {
super();
addCommand(new CalcE());
addCommand(new CalcDOEB());
addCommand(new CalcG());
}
public static void executePFChain() {
Command process = new PFChain();
Context context = new ContextBase();
try {
process.execute(context);
} catch (Exception e) {
System.out.println("errortext");
e.printStackTrace();
}
}
}
我的三个命令类如下所示:
public class CalcDOEB implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculating DOEB...");
return true;
}
}
public class CalcE implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculating E");
return true;
}
}
public class CalcG implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculation G...");
return true;
}
}
现在奇怪的是,他只执行链中的第一个命令。 所有这些都有效,但前提是它们位于命令列表的开头。
当我打开调试器时,我看到它们都在列表中。
此错误从何而来,我该如何解决?
问候,
尼古拉斯
最佳答案
尝试将所有返回语句更改为 false
而不是 true
。
当您返回 true 时,您结束链。因为您不希望链结束,所以您需要返回 false。
要了解更多相关信息,请查看 Javadoc: https://commons.apache.org/proper/commons-chain/apidocs/org/apache/commons/chain/Command.html#CONTINUE_PROCESSING
关于java - Apache 公共(public)链基本示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31807949/