🌿Springboot场景安装运行
# 依赖
LiteFlow提供了liteflow-spring-boot-starter依赖包,提供自动装配功能
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.15.0</version>
</dependency>
为稳定版本,目前jar包已上传中央仓库,可以直接依赖到
# 组件的定义
在依赖了以上jar包后,你需要定义并实现一些组件,确保SpringBoot会扫描到这些组件并注册进上下文。
@LiteflowComponent("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
以此类推再分别定义b,c组件:
@LiteflowComponent("b")
public class BCmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
@LiteflowComponent("c")
public class CCmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
# SpringBoot配置文件
然后,在你的SpringBoot的application.properties或者application.yml里添加配置(这里以properties为例,yaml也是一样的)
更多配置项请参考配置项章节。
liteflow.rule-source=config/flow.xml
# 规则文件的定义
同时,你得在resources下的config/flow.xml
中定义规则:
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
THEN(a, b, c);
</chain>
</flow>
SpringBoot在启动时会自动装载规则文件。
# 执行
声明启动类:
@SpringBootApplication
//把你定义的组件扫入Spring上下文中
@ComponentScan({"com.xxx.xxx.cmp"})
public class LiteflowExampleApplication {
public static void main(String[] args) {
SpringApplication.run(LiteflowExampleApplication.class, args);
}
}
然后你就可以在Springboot任意被Spring托管的类中拿到flowExecutor,进行执行链路:
@Component
public class YourClass{
@Resource
private FlowExecutor flowExecutor;
public void testConfig(){
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", DefaultContext.class);
}
}
提示
这个DefaultContext
是默认的上下文,用户可以用最自己的任意Bean当做上下文传入,如果需要传入自己的上下文,则需要传用户Bean的Class属性,具体请看数据上下文这一章节。
帮助我们改善此文档 (opens new window)
上次更新: 2025/08/28, 22:41:24