Skip to content
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

@WithStateMachine not working when created after the state machine #232

Closed
antonbasic opened this issue Jun 22, 2016 · 3 comments
Closed
Labels
type/bug Is a bug report
Milestone

Comments

@antonbasic
Copy link

When using the @WithStateMachine and the corresponding annotated methods this bean HAS to be created before the state machine is created. So if a bean with @Autowired StateMachine is in package a and @WithStateMachine bean is in package b then @WithStateMachine will have no effect. This is the complete opposite of how it works when using StateMachineListenerAdapter which depends on the state machine being created.

I also asked about this at StackOverflow

@jvalkeal
Copy link
Contributor

jvalkeal commented Jul 7, 2016

Sorry for a late answer. I need to create a test to verify this before I can come up with a fix. Was quickly peekingStateMachineHandlerCallHelper and it may be that caching those beans might cause this as it happens in afterPropertiesSet().

@jvalkeal jvalkeal added the type/bug Is a bug report label Sep 30, 2016
@jvalkeal jvalkeal added this to the 1.2.0.M2 milestone Sep 30, 2016
@TimGuan
Copy link

TimGuan commented Apr 13, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Is a bug report
Projects
None yet
Development

No branches or pull requests

4 participants