Spring 状态机 - 为什么文档使用静态 类

Spring State Machine - Why documentation use static classes

Spring Statemachine 中,主要示例对 @Configuration

使用 static
@Configuration
@EnableStateMachine
static class Config1 extends EnumStateMachineConfigurerAdapter<States, Events> {

还有豆子

@WithStateMachine
static class MyBean {

同时使用 @Autowired:

static class MyApp {
   @Autowired
   StateMachine<States, Events> stateMachine;

是old/sample可以忽略的文档还是有真正的reason/need使用static类?

如果您使用注释 @EnableStateMachine@EnableStateMachineFactory,它们不必是静态的。但是,如果您不使用这些注释并想要构建和配置它,则必须使用静态。

All features for @WithStateMachine can be enabled by using annotation @EnableWithStateMachine which simply imports needed configuration into Spring Application Context. Both @EnableStateMachine and @EnableStateMachineFactory are already annotated with this so there is no need for user to add it again. However if machine is build and configured without a use of configuration adapters, @EnableWithStateMachine must be used order to use features with @WithStateMachine. Idea for this is shown below...

查看此文档:StateMachine

Is it old/sample documentation that can be ignored or is there a real reason/need to use static classes?

是的。

无需静态 - 查看附录中的最新示例 -> 快速示例 - https://docs.spring.io/spring-statemachine/docs/2.1.3.RELEASE/reference/#quick-example and even in the pre-release 3.0.0M1 - https://docs.spring.io/spring-statemachine/docs/3.0.0.M1/reference/#appendices