{"action":"created","issue":{"url":"https://api.github.com/repos/spring-projects/spring-statemachine/issues/370","repository_url":"https://api.github.com/repos/spring-projects/spring-statemachine","labels_url":"https://api.github.com/repos/spring-projects/spring-statemachine/issues/370/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-statemachine/issues/370/comments","events_url":"https://api.github.com/repos/spring-projects/spring-statemachine/issues/370/events","html_url":"https://github.com/spring-projects/spring-statemachine/issues/370","id":233130681,"number":370,"title":"@WithStateMachine method execute tiwce","user":{"login":"playaround88","id":7920738,"avatar_url":"https://avatars2.githubusercontent.com/u/7920738?v=3","gravatar_id":"","url":"https://api.github.com/users/playaround88","html_url":"https://github.com/playaround88","followers_url":"https://api.github.com/users/playaround88/followers","following_url":"https://api.github.com/users/playaround88/following{/other_user}","gists_url":"https://api.github.com/users/playaround88/gists{/gist_id}","starred_url":"https://api.github.com/users/playaround88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/playaround88/subscriptions","organizations_url":"https://api.github.com/users/playaround88/orgs","repos_url":"https://api.github.com/users/playaround88/repos","events_url":"https://api.github.com/users/playaround88/events{/privacy}","received_events_url":"https://api.github.com/users/playaround88/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-06-02T09:44:59Z","updated_at":"2017-06-07T13:22:48Z","closed_at":null,"body":"hi admin\r\n  i am newer of ssm, and i write the simple example of \"quick start\".\r\n  when i run, i found the MyBean with @WithStateMachine  run tiwce，it's depressing!\r\n  can help me? (english is poor, sorry)\r\nlogs\r\n```\r\n信息: Starting beans in phase 0\r\nINFO  [demo] 2017-06-02 17:46:22,372 [com.ai.ssm.business.MyBean.toState1] - to-----state1:1\r\nINFO  [demo] 2017-06-02 17:46:22,377 [com.ai.ssm.business.MyBean.toState1] - to-----state1:2\r\n六月 02, 2017 5:46:22 下午 org.springframework.statemachine.support.LifecycleObjectSupport start\r\n信息: started org.springframework.statemachine.support.DefaultStateMachineExecutor@69e9e330\r\n六月 02, 2017 5:46:22 下午 org.springframework.statemachine.support.LifecycleObjectSupport start\r\n信息: started STATE2 STATE1  / STATE1 / uuid=ec77819b-441a-4a64-bfe5-f7912a555e57 / id=myMachine\r\nINFO  [demo] 2017-06-02 17:46:22,388 [com.ai.ssm.business.MyBean.toState2] - to-----state2:3\r\nINFO  [demo] 2017-06-02 17:46:22,388 [com.ai.ssm.business.MyBean.toState2] - to-----state2:4\r\nINFO  [demo] 2017-06-02 17:46:22,389 [com.ai.ssm.business.MyBean.toState1] - to-----state1:5\r\nINFO  [demo] 2017-06-02 17:46:22,390 [com.ai.ssm.business.MyBean.toState1] - to-----state1:6\r\n```\r\ncode is show below\r\n\r\n```java\r\n@Configuration\r\n@EnableStateMachine\r\npublic class StateMachineConfig extends EnumStateMachineConfigurerAdapter<States,Events> {\r\n\t@Override\r\n\tpublic void configure(StateMachineConfigurationConfigurer<States, Events> config) throws Exception {\r\n\t\tconfig.withConfiguration()\r\n\t\t\t.machineId(\"myMachine\");\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void configure(StateMachineStateConfigurer<States, Events> states) throws Exception {\r\n\t\tstates.withStates()\r\n\t\t\t.initial(States.STATE1)\r\n\t\t\t.states(EnumSet.allOf(States.class));\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void configure(StateMachineTransitionConfigurer<States, Events> transitions) throws Exception {\r\n\t\ttransitions\r\n\t\t\t.withExternal()\r\n\t\t\t\t.source(States.STATE1).target(States.STATE2)\r\n\t\t\t\t.event(Events.EVENT1)\r\n\t\t\t\t.and()\r\n\t\t\t.withExternal()\r\n\t\t\t\t.source(States.STATE2).target(States.STATE1)\r\n\t\t\t\t.event(Events.EVENT2);\r\n\t}\r\n}\r\n```\r\n\r\n```java\r\n@WithStateMachine(id=\"myMachine\")\r\npublic class MyBean {\r\n\tprivate static final Logger LOG=LoggerFactory.getLogger(MyBean.class);\r\n\tprivate static AtomicInteger i=new AtomicInteger(0);\r\n\r\n    @OnTransition(target = \"STATE1\")\r\n    public void toState1() {\r\n    \tint r=i.incrementAndGet();\r\n    \tLOG.info(\"to-----state1:\"+r);\r\n    }\r\n\r\n    @OnTransition(target = \"STATE2\")\r\n    public void toState2() {\r\n    \tint r=i.incrementAndGet();\r\n    \tLOG.info(\"to-----state2:\"+r);\r\n    }\r\n}\r\n```\r\n\r\n```java\r\npublic static void main(String[] args) throws Exception {\r\n\t\tAnnotationConfigApplicationContext ac=new AnnotationConfigApplicationContext();\r\n\t\tac.register(AppConfig.class);\r\n\t\tac.register(StateMachineConfig.class);\r\n\t\tac.scan(\"com.ai.ssm.business\"); // where \"MyBean\" is \r\n\t\tac.refresh();\r\n\t\t\r\n\t\tStateMachine<States, Events> stateMachine = ac.getBean(StateMachine.class);\r\n\t\tstateMachine.start();\r\n\t\tstateMachine.sendEvent(Events.EVENT1);\r\n\t\tstateMachine.sendEvent(Events.EVENT2);\r\n\t\t\r\n\t\tac.close();\r\n\t}\r\n```"},"comment":{"url":"https://api.github.com/repos/spring-projects/spring-statemachine/issues/comments/306792942","html_url":"https://github.com/spring-projects/spring-statemachine/issues/370#issuecomment-306792942","issue_url":"https://api.github.com/repos/spring-projects/spring-statemachine/issues/370","id":306792942,"user":{"login":"jvalkeal","id":50398,"avatar_url":"https://avatars2.githubusercontent.com/u/50398?v=3","gravatar_id":"","url":"https://api.github.com/users/jvalkeal","html_url":"https://github.com/jvalkeal","followers_url":"https://api.github.com/users/jvalkeal/followers","following_url":"https://api.github.com/users/jvalkeal/following{/other_user}","gists_url":"https://api.github.com/users/jvalkeal/gists{/gist_id}","starred_url":"https://api.github.com/users/jvalkeal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvalkeal/subscriptions","organizations_url":"https://api.github.com/users/jvalkeal/orgs","repos_url":"https://api.github.com/users/jvalkeal/repos","events_url":"https://api.github.com/users/jvalkeal/events{/privacy}","received_events_url":"https://api.github.com/users/jvalkeal/received_events","type":"User","site_admin":false},"created_at":"2017-06-07T13:22:48Z","updated_at":"2017-06-07T13:22:48Z","body":"This is a some sort of a bug I need to fix. It's caused by you using\r\n```\r\nconfig\r\n  .withConfiguration()\r\n    .machineId(\"myMachine\");\r\n```\r\nProper way to register statemachine with a non-default bean name is(without using `machineId(\"myMachine\")`)\r\n```\r\n@Configuration\r\n@EnableStateMachine(name = \"myMachine\")\r\nclass XXX {}\r\n```\r\nWhich then works correctly with `@WithStateMachine(id=\"myMachine\")` where you should get method called only once.\r\n\r\nAnyway, afaik it should not break like this and there's is some sort of bug around registration I need to fix. Thanks for finding this!"}}
{"actor":{"display_login":"jvalkeal"}}