我想使用StateMachine
为动态实例化添加几个StateMachineFactory
配置。但是@EnableStateMachineFactory
注释允许命名工厂。如何为每个配置命名(即扩展EnumStateMachineConfigurerAdapter
)?
否则,如果可能的话,在配置定义中有一个如何使用setMachineID
方法的示例会很有用。
答案 0 :(得分:3)
使用Spring“@Configuration”类进行这些enable
注释只需定义在应用程序上下文中注册的bean名称。最容易用例子解释:
@EnableStateMachine
StateMachine
作为bean stateMachine
。
@EnableStateMachine(name = "fooMachine")
StateMachine
作为bean fooMachine
。
@EnableStateMachine(name = {StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, "fooMachine"})
StateMachine
作为bean stateMachine
,其中包含bean别名fooMachine
。
@EnableStateMachineFactory
StateMachineFactory
作为bean stateMachineFactory
。
@EnableStateMachineFactory(name = "fooMachineFactory")
StateMachineFactory
作为bean fooMachineFactory
。
@EnableStateMachineFactory(name = {StateMachineSystemConstants.DEFAULT_ID_STATEMACHINEFACTORY, "fooMachineFactory"})
StateMachineFactory
作为bean stateMachineFactory
,其中包含bean别名fooMachineFactory
。
除此之外,@Configuration
类(扩展StateMachineConfigurerAdapter)的名称无关紧要。在Spring中思考一个@Configuration
类也被创建为bean,这意味着下面的类将作为bean myConfig.MachineFactoryConfig
存在于Spring Application Context中。在Spring中只记得一件事,因为命名错误的类可能导致bean覆盖!
public class MyConfig {
@Configuration
@EnableStateMachineFactory
public static class MachineFactoryConfig extends StateMachineConfigurerAdapter<String, String> {
}
}
machineId
的内容我刚向文档State Machine ID添加了一个新部分。 (仅在快照构建中,直到我们获得下一个版本)