我是Spring状态机的新手我有下面给出的状态配置我需要在mysql中使用JPA来保持状态更改。任何适当的例子对我也很有帮助。提前致谢
@Configuration
@EnableStateMachine(name = "machine1")
public class Config extends StateMachineConfigurerAdapter<String, String>{
@Override
public void configure(StateMachineConfigurationConfigurer<String, String> config) throws Exception {
config.withConfiguration().autoStartup(true).listener(listener());
}
@Override
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
states
.withStates()
.initial("S1")
.state("S1")
.state("S2",null,action1())
.state("S3");
}
@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
transitions
.withExternal()
.source("S1")
.target("S2")
.event("E1")
.and().withExternal()
.source("S2")
.target("S3")
.event("E2");
}
}
答案 0 :(得分:2)
jpa-config只是保持数据库中机器配置(状态,转换等)的示例。如果您使用其他方法(javadsl或uml)进行配置,则不需要此操作。这种支持正在增加,因为有些人希望有一种方法来修改机器配置,而无需再次编译源代码。我目前正致力于通过相同类型的弹簧数据存储库抽象为持久化机器添加更好的支持,这应该落在1.2.8。
其他一些示例是如何手动完成的一些示例。目前这个过程确实非常手动,低水平而且相当繁琐。如果您不急,我建议使用1.2.x分支中的1.2.8快照。即新的样本datajpapersist在运行时显示更清晰的模型持久化机器。