我已经在UML中实现了Spring statemachine,并试图实现连接池。 我的配置类是Spring状态机池错误
@Configuration
public class CambodiaStateMachine {
@Autowired
private ApplicationContext appContext;
@Bean
public StateMachineListener<String, String> listener() {
return new StateMachineListenerAdapter<String, String>() {
@Override
public void stateChanged(State<String, String> from, State<String, String> to) {
System.out.println("State change to " + to.getId());
}
};
}
@Bean(name = "stateMachineTarget")
@Scope(scopeName="prototype")
public StateMachine<String, String> stateMachineTarget() throws Exception {
Builder<String, String> builder = StateMachineBuilder.<String, String>builder();
builder.configureConfiguration()
.withConfiguration()
.machineId("cambodia")
.autoStartup(true);
builder.configureModel().withModel().factory(modelFactory());
builder.configureConfiguration().withConfiguration().beanFactory(appContext.getAutowireCapableBeanFactory());
return builder.build();
}
@Bean
public StateMachineModelFactory<String, String> modelFactory() {
return new UmlStateMachineModelFactory("classpath:stm/model.uml");
}
@Bean
public CommonsPool2TargetSource poolTargetSource() {
CommonsPool2TargetSource pool = new CommonsPool2TargetSource();
pool.setMaxSize(10);
pool.setTargetBeanName("stateMachineTarget");
return pool;
}
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public ProxyFactoryBean stateMachine() {
ProxyFactoryBean pfb = new ProxyFactoryBean();
pfb.setTargetSource(poolTargetSource());
return pfb;
}
}
,我得到一个错误
产生的原因:java.lang.IllegalStateException:无法为bean创建范围代理 “scopedTarget.stateMachine ':在创建代理时确定的目标类型不能为
。 现在我决定去体验一下,并删除
proxyMode = ScopedProxyMode.TARGET_CLASS
错误是没有更多的,但没有观察到预期的行为。没有游泳池,只有一台机器在运行。
我看过这个bug here但是看不到解决方案。
顺便说一句你可以标记你的问题的答案,如果你认为这些答案;) –
对不起,我刚刚检查。有效!! Thankyou –