简体   繁体   中英

Spring State machine JPA persistence

I am new to Spring state machine I have the state configuration given below I need to persist the state changes using JPA in mysql. Any proper example is also very helpful for me. Thanks in advance

@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 is just an example keeping machine configuration(states, transitions, etc) in a DB. You don't need this if you use other means(javadsl or uml) of making a config. This support were adding as some people wanted to have a way to modify machine configs without compiling sources again. I'm currently working on adding better support for persisting machine via same type of spring data repository abstractions, this should land in 1.2.8.

Some other samples are some examples how thing can be done manually. Currently this process is indeed very manual, low level and rather cumbersome. If you not in rush, I'd recommend using 1.2.8 snapshots from 1.2.x branch. ie there's new sample datajpapersist showing cleaner model persisting machine at runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM