用activiti做流程引擎时,我们需要定制一些全局配置,如主键的生成规则,全局事件等。
在activiti5中,是这样实现的
@Bean(name = "processEngineConfiguration")
public ProcessEngineConfigurationImpl processEngineConfiguration() {
SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
processEngineConfiguration.setDataSource(druidDataSource());
processEngineConfiguration.setTransactionManager(annotationDrivenTransactionManager());
//设置全局事件监听
processEngineConfiguration.setTypedEventListeners(this.getGlobalActivitiEventListener());
//重写节点行为
processEngineConfiguration.setActivityBehaviorFactory(new ActivityBehaviorFactory());
//设置主键生成
processEngineConfiguration.setIdGenerator(new ActivitiIdGenerator());
//设置函数
processEngineConfiguration.setBeans(FunctionFactory.getFunctionBeans());
return processEngineConfiguration;
}
但是这样的代码,在flowable不起作用。经分析,调整代码如下:
@Bean
public EngineConfigurationConfigurer<SpringProcessEngineConfiguration> customIdGeneratorConfigurer() {
return engineConfiguration -> {engineConfiguration.setIdGenerator( customIdGenerator());
engineConfiguration.setActivityBehaviorFactory(activityBehaviorFactory());
engineConfiguration.setTransactionManager(transactionManager);
};
}
经测试,功能OK!
我的博客即将入驻“云栖社区”,诚邀技术同仁一同入驻。