0

我已经在 UML 中实现了 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

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

我在这里看到了这个错误,但没有看到解决方案。

4

1 回答 1

1

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

于 2017-05-05T08:47:59.770 回答