【问题标题】:deriving spring state machine from database从数据库导出弹簧状态机
【发布时间】:2017-10-30 21:47:31
【问题描述】:

是否可以将spring-state-machine 的状态、动作和转换的配置信息存储在数据库中?这个想法是在启动时加载该配置数据并使用该数据创建状态机。这样,我们可以随时修改状态、动作和转换,并重新加载应用程序以修改状态机图。

其次,我对 spring-state-machine 提供的persist 功能有点困惑。是否要保留历史/活动日志信息,说明哪个用户执行了哪些操作,从而导致某些状态转换?还是状态机的某些内部状态有助于重新加载它。如果我想在数据库中使用此类活动日志,spring-state-machine 框架是否提供存储该数据的功能?

【问题讨论】:

    标签: spring-boot spring-statemachine


    【解决方案1】:

    Medium 上的文章说要配置状态机

    @Override
    public void configure(StateMachineTransitionConfigurer<States, Events> transitions) 
    throws Exception {
        transitions
       .withExternal()
       .source(States.ORDERED)
       .target(States.ASSEMBLED)
       .event(Events.assemble)
       .and()
       .withExternal()
       .source(States.ASSEMBLED)
       .target(States.DELIVERED)
       .event(Events.deliver)
       .and()
       .withExternal()
       .source(States.DELIVERED)
       .target(States.INVOICED)
       .event(Events.release_invoice)
    

    所以我的想法是,如果你有一个名为 tbl_transitions 的表,其中有列

    id | from_state | to_state | event
    -----------------------------------
    1  | ORDERED    | ASSEMBELED | assemble
    2  | ASSEMBLED  | DELIVERED  | deliver
    3  | DELIVERED  | INVOICED   | release_invoice
    

    你可以从这个表中读取数据,循环它并以“非流利”的方式构建你的转换。我没有尝试过,但这是一个想法。

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多