FAQ

This chapter answers the questions that Spring Statemachine users most often ask.

State Changes

How can I automatically transit to the next state?

You can choose from three approaches:spring-doc.cn

  • Implement an action and send an appropriate event to a state machine to trigger a transition into the proper target state.spring-doc.cn

  • Define a deferred event within a state and, before sending an event, send another event that is deferred. Doing so causes the next appropriate state transition when it is more convenient to handle that event.spring-doc.cn

  • Implement a triggerless transition, which automatically causes a state transition into the next state when state is entered and its actions has been completed.spring-doc.cn

Extended State

How I can initialize variables on state machine start?

An important concept in a state machine is that nothing really happens unless a trigger causes a state transition that then can fire actions. However, having said that, Spring Statemachine always has an initial transition when a state machine is started. With this initial transition, you can run a simple action that, within a StateContext, can do whatever it likes with extended state variables.spring-doc.cn