🍩Solon场景安装运行
# 依赖
对于使用solon框架用户。LiteFlow也提供了依赖:
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-solon-plugin</artifactId>
<version>2.15.0</version>
</dependency>
为稳定版本,目前jar包已上传中央仓库,可以直接依赖到
# 组件的定义
在依赖了以上jar包后,你需要定义并实现一些组件,这里需要注意的是@Component
注解应为Solon框架提供的:
import org.noear.solon.annotation.Component;
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
以此类推再分别定义b,c组件:
@Component("b")
public class BCmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
@Component("c")
public class CCmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
# 配置文件
然后,需要定义application.properties或者application.yml里添加配置(这里以properties为例,yaml也是一样的)
更多配置项请参考Solon下的配置项章节。
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>
Solon在启动时会自动装载规则文件。
# 执行
声明启动类:
@SolonMain
@Import(profiles="classpath:/application.properties")
public class LiteflowExampleApplication {
public static void main(String[] args) {
Solon.start(App.class, args);
}
}
然后你就可以在任意被Solon托管的类中拿到flowExecutor,进行执行链路:
@Component
public class YourClass{
@Inject
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