java - Spring状态机池错误

标签 java spring spring-statemachine

我已经在 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;
    }

}

我收到一个错误

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。

关于java - Spring状态机池错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43782148/

相关文章:

java - Android MediaPlayer `Prepared` 和 `OnPlayStarted` 问题

Spring Cloud 配置服务器。属性中的环境变量

java - Spring 状态机 JPA 持久化

java - 如何将连接信息传递给可运行对象?

java - 如何在Java中将.jpeg图像转换为.jif? (从EXIF到JFIF)

java - Jackson Databind ObjectMapper ConvertValue 与自定义映射实现

java - 使用 SpringBatch JdbcCursorItemReader 并将 List 作为 NamedParameters

java - 使用 Hibernate 和 Spring 的一对多映射

java - Spring状态机嵌套机器同步运行