Skip to content

I just encounter a problem when using spring state machine @WithStateMachine. #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
chenlei65368 opened this issue May 30, 2019 · 0 comments

Comments

@chenlei65368
Copy link

I just encounter a problem when using spring state machine @WithStateMachine.
@WithStateMachine just work when I use it on inner class which defined in the class annotated by @EnableStateMachine, but when I define class in other place it seems not work.
Here is my code:
`@Configuration @EnableStateMachine public class StateMachineConfig extends EnumStateMachineConfigurerAdapter { private Logger logger = LoggerFactory.getLogger(getClass());

@OverRide
public void configure(StateMachineStateConfigurer<States, Events> states)
throws Exception {
states
.withStates()
.initial(States.UNPAID)
.states(EnumSet.allOf(States.class));
}

@OverRide
public void configure(StateMachineTransitionConfigurer<States, Events> transitions)
throws Exception {
transitions
.withExternal()
.source(States.UNPAID).target(States.WAITING_FOR_RECEIVE)
.event(Events.PAY)
.and()
.withExternal()
.source(States.WAITING_FOR_RECEIVE).target(States.DONE)
.event(Events.RECEIVE);
}

@OverRide
public void configure(StateMachineConfigurationConfigurer<States, Events> config)
throws Exception {
config
.withConfiguration()
.autoStartup(true);
//.listener(listener());
}

//
//@bean
//public StateMachineListener<States, Events> listener() {
// return new StateMachineListenerAdapter<States, Events>() {
// @OverRide
// public void transition(Transition<States, Events> transition) {
// if (transition.getTarget().getId() == States.UNPAID) {
// logger.info("UNPAID");
// return;
// }
// if (transition.getSource().getId() == States.UNPAID
// && transition.getTarget().getId() == States.WAITING_FOR_RECEIVE) {
// logger.info("WAITING_FOR_RECEIVE");
// return;
// }
// if (transition.getSource().getId() == States.WAITING_FOR_RECEIVE
// && transition.getTarget().getId() == States.DONE) {
// logger.info("DONE");
// return;
// }
// }
// };
//}
@WithStateMachine
public class Action {
private Logger logger = LoggerFactory.getLogger(getClass());

@OnTransition(target = "UNPAID")
public void create() {
    logger.info("UNPAID");
}

@OnTransition(source = "UNPAID", target = "WAITING_FOR_RECEIVE")
public void pay() {
    logger.info("WAITING_FOR_RECEIVE");
}

@OnTransition(source = "WAITING_FOR_RECEIVE", target = "DONE")
public void receive() {
    logger.info("DONE");
}

}
}`
but when I define Action in another class file, it is not work.
My pom

org.springframework
spring-core
4.3.3.RELEASE


org.springframework
spring-messaging
1.2.3.RELEASE

Originally posted by @TimGuan in #232 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant