gpt4 book ai didi

java - 如何访问 Spring StateMachine 配置数据

转载 作者:行者123 更新时间:2023-11-30 05:48:16 24 4
gpt4 key购买 nike

我有一个 Spring 状态机,使用 EnumStateMachineConfigurerAdapter 配置,并用 @EnableStateMachineFactory 注释

一切顺利,我可以使用工厂创建状态机:

AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(MyStateMachineConfig.class);
context.refresh();
StateMachineFactory stateMachineFactory = context.getBean(StateMachineFactory.class);

但是我需要对状态机的配置进行一些反省。基本上我想获得所有最终状态的列表,以供我记录。

此信息可在 org.springframework.statemachine.config.StateMachineConfig 中找到,我可以在调试时知道它的实例已创建。但它似乎没有注册为bean,并且我无法通过调用来访问它:

context.getBean(StateMachineConfig.class);

原因:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.statemachine.config.StateMachineConfig<?, ?>' available

最佳答案

您可以注册自己的StateMachineModelVerifier并访问各州数据 - 有一个公共(public) isEnd() StateData 上的方法对象。

@Override
public void configure(StateMachineConfigurationConfigurer<States, Events> config)
throws Exception {
config
.withVerifier()
.enabled(true)
.verifier(cusomVerifier());
}

@Bean
public StateMachineModelVerifier customVerifier() {
return new CustomVerifier();
}

class CustomVerifier extends DefaultStateMachineModelVerifier {
@Override
public void verify(StateMachineModel model) {
super.verify(model); // call the existing sanity check model verifier
Collection<StateData<State, Event> statesData = model.getStatesData().getStateData();
//log your stuff
}
}

关于java - 如何访问 Spring StateMachine 配置数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54457443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com