🌵其他场景安装运行
# 说明
虽说Springboot/Spring已经成为了Java项目中的标配,但是为了照顾到启用其他框架的小伙伴(其更重要的原因是强耦合Spring我始终觉得是瑕疵,有点代码洁癖),现在在非Spring体系的环境中也能使用LiteFlow框架带来的便捷和高效。
LiteFlow文档中提到的98%以上的特性功能都能在非Spring体系中生效。其中不生效的特性和功能有:
- ruleSource的模糊路径匹配特性在非Spring体系下不生效
- LiteflowComponent在非Spring体系下无法使用
- 监控功能在非Spring体系中无法使用
# 依赖
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-core</artifactId>
<version>2.15.0</version>
</dependency>
为稳定版本,目前jar包已上传中央仓库,可以直接依赖到
# 定义你的组件
你需要定义并实现一些组件。
public class ACmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
以此类推再分别定义b,c组件:
public class BCmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
public class CCmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
# 规则文件的配置
resources的config/flow.xml
中如下配置:
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.component.AComponent"/>
<node id="b" class="com.yomahub.liteflow.test.component.BComponent"/>
<node id="c" class="com.yomahub.liteflow.test.component.CComponent"/>
</nodes>
<chain name="chain1">
THEN(a, b, c);
</chain>
</flow>
# 初始化你的FlowExecutor执行器
通过以下代码你可以轻易的初始化FlowExecutor
处理器:
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("config/flow.xml");
FlowExecutor flowExecutor = FlowExecutorHolder.loadInstance(config);
更多配置项请参考配置项章节。
提示
要注意的是,不建议每次执行流程都去初始化FlowExecutor
,这个对象的初始化工作相对比较重,全局只需要初始化一次就好了。建议在项目启动时初始化或者第一次执行的时候初始化。
# 用FlowExecutor执行
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", DefaultContext.class);
提示
这个DefaultContext
是默认的上下文,用户可以用最自己的任意Bean当做上下文传入,如果需要传入自己的上下文,则需要传用户Bean的Class属性,具体请看数据上下文这一章节。
帮助我们改善此文档 (opens new window)
上次更新: 2025/08/28, 22:41:24