我正在使用activiti 5.18。
幕后花絮:通过工作流路由的任务很少。其中一些任务可以升级。我已将我的升级监听器编写如下。
@Component
public class EscalationTimerListener implements ExecutionListener {
@Autowired
ExceptionWorkflowService exceptionWorkflowService;
@Override
public void notify(DelegateExecution execution) throws Exception {
//Process the escalated tasks here
this.exceptionWorkflowService.escalateWorkflowTask(execution);
}
}
现在,当我启动tomcat服务器时,即使在加载整个spring上下文之前,activiti框架也会在内部调用侦听器。因此exceptionWorkflowService为null(因为spring尚未取消它!)并且我的代码中断了。
注意:仅当服务器在任务升级时没有运行并且此后我启动/重新启动服务器时,才会发生这种情况。如果我的服务器在升级期间已经在运行,则该过程将顺利进行。因为当服务器启动时,它已经注入了服务,而我的监听器后来又触发了。
我尝试使用@DependsOn
注释延迟活动配置,以便在ExceptionWorkflowService初始化如下后加载。
@Bean
@DependsOn({ "dataSource", "transactionManager","exceptionWorkflowService" })
public SpringProcessEngineConfiguration getConfiguration() {
final SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
config.setAsyncExecutorActivate(true);
config.setJobExecutorActivate(true);
config.setDataSource(this.dataSource);
config.setTransactionManager(this.transactionManager);
config.setDatabaseSchemaUpdate(this.schemaUpdate);
config.setHistory(this.history);
config.setTransactionsExternallyManaged(this.transactionsExternallyManaged);
config.setDatabaseType(this.dbType);
// Async Job Executor
final DefaultAsyncJobExecutor asyncExecutor = new DefaultAsyncJobExecutor();
asyncExecutor.setCorePoolSize(2);
asyncExecutor.setMaxPoolSize(50);
asyncExecutor.setQueueSize(100);
config.setAsyncExecutor(asyncExecutor);
return config;
}
但这会产生循环引用错误。
我还尝试过将一个bean添加到SpringProcessEngineConfiguration
中,如下所示。
Map<Object, Object> beanObjectMap = new HashMap<>();
beanObjectMap.put("exceptionWorkflowService", new ExceptionWorkflowServiceImpl());
config.setBeans(beanObjectMap);
,并且在我的侦听器中的访问与:
Map<Object, Object> registeredBeans = Context.getProcessEngineConfiguration().getBeans();
ExceptionWorkflowService exceptionWorkflowService = (ExceptionWorkflowService) registeredBeans.get("exceptionWorkflowService");
exceptionWorkflowService.escalateWorkflowTask(execution);
这可以但有效,但是我的存储库已自动连接到尚未初始化的服务中!因此,它再次在服务层中引发错误:)
那么有什么方法可以让我仅在加载整个spring上下文后触发升级监听器吗?
答案 0 :(得分:0)
您是否尝试过将类绑定到ApplicationListener? 不知道它是否会工作,但同样不确定我为什么在启动时实际上执行了您的侦听器代码。
答案 1 :(得分:0)
尝试使用Java类或委托表达式设置侦听器的实现类型,然后在该类中实现JavaDelegate而不是ExecutionListener。