Vineeth Bhaskaran
Vineeth Bhaskaran

Reputation: 2281

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

}

Upvotes: 1

Views: 3525

Answers (1)

Janne Valkealahti
Janne Valkealahti

Reputation: 2646

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. i.e. there's new sample datajpapersist showing cleaner model persisting machine at runtime.

Upvotes: 3

Related Questions