gpt4 book ai didi

java - Spring 状态机 JPA 持久化

转载 作者:行者123 更新时间:2023-11-29 04:23:38 25 4
gpt4 key购买 nike

我是 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");
}

}

最佳答案

jpa-config 只是一个将机器配置(状态、转换等)保存在数据库中的示例。如果您使用其他方式(javadsl 或 uml)进行配置,则不需要它。添加此支持是因为有些人希望有一种无需再次编译源代码即可修改机器配置的方法。我目前正致力于通过相同类型的 spring 数据存储库抽象为持久化机器添加更好的支持,这应该会在 1.2.8 中实现。

其他一些示例是如何手动完成操作的一些示例。目前这个过程确实是非常手工化的,层次低,比较繁琐。如果您不着急,我建议您使用 1.2.x 分支的 1.2.8 快照。即有新样本 datajpapersist在运行时显示更清洁的模型持久化机器。

关于java - Spring 状态机 JPA 持久化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47610657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com