我从这个论坛获得了帮助:https://community.alfresco.com/thread/225090-spring-boot-activiti-5180-and-drools-integration-issue.我能够自动装配ProcessEngine,获得流程引擎配置,然后在添加部署程序时我受到了打击。代码片段是:
SpringProcessEngineConfiguration sp = (SpringProcessEngineConfiguration)
processEngine.getProcessEngineConfiguration();
List<Deployer> listDeployer = new ArrayList<Deployer>();
listDeployer.add(new RulesDeployer());
sp.setCustomPostDeployers(listDeployer); // <--setCustomPostDeployers function is not called
如何实现此目的并调用setCustomPostDeployers函数将Drools与Activiti集成。任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
我花了一些时间弄清楚它,但是在阅读了一些有趣的文章和文档之后,我终于使用Activiti,Spring-Boot和Drools创建了一个示例。
在您的情况下,您要在使用processEngine
之前修改现有的SpringBootConfiguration,但是根据我的测试,由于已经读取了资源,因此在此添加自定义部署程序为时已晚。然后,您必须更早地设置配置。
文档通常指出要更改“ activiti.cfg.xml”,但这仅用于spring
,而对于spring-boot
则无效。然后的想法是生成一个Spring Boot用来做的配置类。
@Configuration
public class ProcessEngineConfigDrlEnabled {
@Autowired
private DataSource dataSource;
@Autowired
private PlatformTransactionManager transactionManager;
@Bean
public SpringProcessEngineConfiguration processEngineConfiguration() {
SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
try {
config.setDeploymentResources(getBpmnFiles());
} catch (IOException e) {
e.printStackTrace();
}
config.setDataSource(dataSource);
config.setTransactionManager(transactionManager);
//Here the rulesdeployer is added.
config.setCustomPostDeployers(Arrays.asList(new RulesDeployer()));
return config;
}
/*Read folder with BPMN files and folder with DLR files */
private Resource[] getBpmnFiles() throws IOException {
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
Resource[] bpmnResources = resourcePatternResolver.getResources("classpath*:" + BPMN_PATH + "**/*.bpmn20.xml");
Resource[] drlResources = resourcePatternResolver.getResources("classpath*:" + DRL_PATH + "**/*.drl");
return (Resource[]) ArrayUtils.addAll(bpmnResources, drlResources);
}
@Bean
public ProcessEngineFactoryBean processEngine() {
ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
factoryBean.setProcessEngineConfiguration(processEngineConfiguration());
return factoryBean;
}
...
}
通常,此类必须位于Spring Boot可以读取的数据包中(在主类的数据包层次结构中)。
在此示例中,我拥有@Autowired
数据源和transactionManager以使用默认配置中的原始资源。如果不是,则必须实现您的并将其添加到配置中。