0
我想在我的項目中使用Spring Statemachine框架,但是我在編譯時遇到了一個建築bean定義錯誤。buildBeanDefinition與Spring Statemachine Framework失敗
2017-07-25 16:37:25.462:WARN:oejd.DeploymentManager:Scanner-1: Unable to reach node goal: started
java.lang.NoSuchMethodError: org.springframework.beans.factory.support.RootBeanDefinition.setTargetType(Lorg/springframework/core/ResolvableType;)V
at org.springframework.statemachine.config.configuration.StateMachineConfiguration.buildBeanDefinition(StateMachineConfiguration.java:109)
at org.springframework.statemachine.config.common.annotation.AbstractImportingAnnotationConfiguration.registerBeanDefinitions(AbstractImportingAnnotationConfiguration.java:92)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:352)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:143)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:333)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
我在我的Spring MVC應用程序中跟隨step 7。我沒有使用SpringBoot,但我不認爲我錯過了任何子文件。
這裏是我的StateMachineConfig文件代碼:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
import org.springframework.statemachine.listener.StateMachineListener;
import org.springframework.statemachine.listener.StateMachineListenerAdapter;
import org.springframework.statemachine.state.State;
import java.util.EnumSet;
@Configuration
@EnableStateMachine
public class StateMachineConfig
extends EnumStateMachineConfigurerAdapter<States, Events> {
@Override
public void configure(StateMachineConfigurationConfigurer<States, Events> config)
throws Exception {
config
.withConfiguration()
.autoStartup(true)
.listener(listener());
}
@Override
public void configure(StateMachineStateConfigurer<States, Events> states)
throws Exception {
states
.withStates()
.initial(States.SI)
.states(EnumSet.allOf(States.class));
}
@Override
public void configure(StateMachineTransitionConfigurer<States, Events> transitions)
throws Exception {
transitions
.withExternal()
.source(States.SI).target(States.S1).event(Events.E1)
.and()
.withExternal()
.source(States.S1).target(States.S2).event(Events.E2);
}
@Bean
public StateMachineListener<States, Events> listener() {
return new StateMachineListenerAdapter<States, Events>() {
@Override
public void stateChanged(State<States, Events> from, State<States, Events> to) {
System.out.println("State change to " + to.getId());
}
};
}
}
這是我嘗試使用的StateMachine中(注控制器:我刪除了的statemachine作爲的IntelliJ的實例化上面的標籤@Autowired不停地說「的‘的StateMachine’類型沒有發現豆」這可能是我的問題的罪魁禍首):?
@Controller
@RequestMapping("/")
public class HomeController {
private StateMachine<States, Events> stateMachine;
@RequestMapping(method = RequestMethod.GET)
public String index() {
stateMachine.sendEvent(Events.E1);
return "redirect:/target/list";
}
}
這很有道理。有沒有辦法知道我需要使用statemachine的jar版本?我的項目正在編譯和運行,我只是將上面的代碼添加到現有代碼庫中,以及POM文件中的spring-statemachine-core依賴項。 – A21
謝謝,這有幫助。我將一些核心Spring框架的現有POM版本從3.2.5.RELEASE升級到4.2.3.RELEASE。 – A21