編程方式整合Spring和Activiti

一、配置並注入org.activiti.spring.SpringProcessEngineConfiguration,經過它設置一系列參數: java

@Bean
	public SpringProcessEngineConfiguration processEngineConfiguration(){
		SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
		processEngineConfiguration.setDataSource(this.dataSource);
		processEngineConfiguration.setTransactionManager(this.jpaTransactionManager());
		processEngineConfiguration.setDatabaseSchemaUpdate("true");
		Resource resource = new ClassPathResource("com/sfauto/config/leave.zip");
		processEngineConfiguration.setDeploymentResources(new Resource[]{resource});
		return processEngineConfiguration;
	}



注意 setDeployResources方法,經過它能夠自動部署流程(若是已部署過就不部署)。

二、注入ProcessEngineFactoryBean spring

@Bean
	public ProcessEngineFactoryBean processEngineFactory(){
		ProcessEngineFactoryBean processEngineFactory = new ProcessEngineFactoryBean();
		processEngineFactory.setProcessEngineConfiguration(this.processEngineConfiguration());
		return processEngineFactory;
	}



三、經過processEngineFactory注入activiti的各種service

@Bean
	public RepositoryService repositoryService() throws Exception{
		return this.processEngineFactory.getObject().getRepositoryService();
	}
	
	@Bean
	public RuntimeService runtimeService() throws Exception{
		return this.processEngineFactory.getObject().getRuntimeService();
	}
	
	@Bean
	public FormService formService() throws Exception{
		return this.processEngineFactory.getObject().getFormService();
	}
	
	@Bean
	public IdentityService identityService() throws Exception{
		return this.processEngineFactory.getObject().getIdentityService();
	}
	
	@Bean
	public TaskService taskService() throws Exception{
		return this.processEngineFactory.getObject().getTaskService();
	}
	
	@Bean
	public HistoryService historyService() throws Exception{
		return this.processEngineFactory.getObject().getHistoryService();
	}
	
	@Bean
	public ManagementService managementService() throws Exception{
		return this.processEngineFactory.getObject().getManagementService();
	}
相關文章
相關標籤/搜索