Spring 状态机池错误

Spring state-machine pooling error

我已经在 UML 中实现了 Spring 状态机,并且正在尝试实现连接池。 我的配置 class 是

@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;
    }

}

我遇到了一个错误

Caused by: java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.stateMachine': Target type could not be determined at the time of proxy creation

。 现在我试着玩它并删除了

proxyMode = ScopedProxyMode.TARGET_CLASS

不再有错误,但没有观察到预期的行为。没有游泳池,只有一台机器 运行。

我已经看到这个错误 here 但没有找到解决方案。

该问题与 https://jira.spring.io/browse/SPR-15042 相关。检查 Spring 框架版本,因为它适用于 4.3.3 和 4.3.6,但不适用于 4.3.4、4.3.5。