編程方式整合Spring和Activiti

jopen 8年前發布 | 31K 次閱讀 Spring JEE框架

1、配置并注入org.activiti.spring.SpringProcessEngineConfiguration,通過它設置一系列參數:

@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方法,通過它可以自動部署流程(如果已部署過就不部署)。

2、注入ProcessEngineFactoryBean

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



3、通過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();
    }



來自: http://my.oschina.net/u/2453016/blog/601915

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!