【发布时间】:2019-05-31 10:36:26
【问题描述】:
我需要创建 StateMachine 来管理任务。我知道如何创建状态机,但我不能使用它。这是我的第一个状态机,也是第一个 MongoDB 项目。
我的状态机:
@Configuration
@EnableStateMachine
class QuestStateMachineConfig : EnumStateMachineConfigurerAdapter<QuestState, QuestEvent>() {
@Throws(Exception::class)
override fun configure(states: StateMachineStateConfigurer<QuestState, QuestEvent>) {
states.withStates()
.initial(QuestState.AWAITING)
.state(QuestState.ASSIGNED)
.state(QuestState.MARKED_TO_REJECT)
.state(QuestState.IN_PROGRESS)
.end(QuestState.DONE)
.end(QuestState.REJECTED)
}
@Throws(Exception::class)
override fun configure(transitions: StateMachineTransitionConfigurer<QuestState, QuestEvent>) {
transitions.withExternal()
.source(QuestState.AWAITING).target(QuestState.ASSIGNED).event(QuestEvent.ASSIGN)
.and()
...
}
我需要创建一个状态为 AWAITING 的任务,接下来我必须在用户使用更新操作时对其进行修改并将其保存在数据库中。怎么做?以及如何监听这个操作的 onSuccess 回调?
【问题讨论】:
标签: spring kotlin spring-statemachine