【发布时间】:2021-11-21 06:34:34
【问题描述】:
为此,我有以下配置
@Override
public void configure(final StateMachineStateConfigurer<States, Events> states) throws Exception {
states
.withStates()
.states(EnumSet.allOf(States.class))
.initial(States.NEW)
.end(States.ERROR)
.end(States.DELIVER);
}
及以下过渡
@Override
public void configure(final StateMachineTransitionConfigurer<States, Events> transitions)
throws Exception {
transitions
.withExternal()
.source(States.NEW).target(States.PACKAGED).event(Events.pack)
.and()
.withExternal()
.source(States.PACKAGED).target(States.PROCESS).event(Events.process)
.and()
.withExternal()
.source(States.PACKAGED).target(States.ERROR).event(Events.error)
.and()
.withExternal()
.source(States.PROCESS).target(States.DELIVER).event(Events.deliver)
.and()
.withExternal()
.source(States.PROCESS).target(States.ERROR).event(Events.error);
}
我正在尝试纠正一个条件,即在打包或处理订单时,如果遇到任何错误,订单的状态应该是错误状态。 我注意到在配置转换时可以添加转换操作,如下所示
public Action<States, Events> packageAction() {
// Packaging logic
if(packed){
return context -> context.getStateMachine().sendEvent(Events.process);
}else{
return context -> context.getStateMachine().sendEvent(Events.error);
}
}
但运行应用程序后它不起作用。 这是有条件地发布事件的正确方法吗?
【问题讨论】:
-
你能发布错误日志吗?
标签: spring spring-boot spring-statemachine