我已經在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 –