Master LiteFlow: Simplify Complex Business Logic in SpringBoot
This article introduces LiteFlow, a lightweight Java workflow engine, explains its key features, rule syntax, IDE plugin, integration steps with SpringBoot, component development, context handling, and provides practical code examples for building a complex order‑price calculation flow.
LiteFlow Overview
LiteFlow is a lightweight, powerful workflow engine framework for orchestrating complex componentized business logic in Java projects. It allows defining business logic as components and linking them through concise rule files.
Key Features
Unified component definition using Spring annotations like @Component Lightweight rule files (XML, JSON, YML) with a five‑minute learning curve
Support for serial, parallel, switch, and conditional orchestration
Dynamic rule hot‑refresh without restarting the application
Compatibility with SpringBoot, Spring, and other Java projects
IDEA Plugin
The LiteFlowX plugin provides intelligent hints, syntax highlighting, component‑to‑rule navigation, and a toolbox for rule files.
Rule Expressions
Serial orchestration uses the THEN keyword, parallel uses WHEN, switch uses SWITCH, conditional uses IF, and else/elif use ELSE and ELIF. Example XML snippets illustrate each pattern.
Integration Steps
Add the Maven dependency liteflow-spring-boot-starter (v2.8.5) to pom.xml and configure application.yml with liteflow.rule-source: liteflow/*.el.xml. Define components by extending NodeComponent (or NodeSwitchComponent) and implement process() and optional isAccess() methods.
Rule Files and Main Flow
Sub‑chains (e.g., promotion calculations) and the main chain are described in XML, linking components such as checkCmp, promotionChain, couponCmp, and conditional postage components.
Controller Invocation
A Spring MVC controller injects FlowExecutor and calls execute2Resp("mainChain", request, PriceContext.class) to run the flow and obtain the result.
Context Management
All data is stored in a shared PriceContext object, which holds order details, member info, coupons, promotion packs, price steps, and logs. Components read and write this context to pass information without explicit parameters.
Conclusion
LiteFlow simplifies complex business processes, making them clear and maintainable with minimal code. Its concise rule language and hot‑refresh capability enable rapid development.
Resources
Project repository: https://gitee.com/dromara/liteFlow
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
