4.spring boot activiti 整合

作者: 会灰的大飞狼 | 来源:发表于2017-04-11 15:31 被阅读7246次

    1.pom.xml

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-spring-boot-starter-basic</artifactId>
        <version>5.22.0</version>
    </dependency>
    

    2. resources目录下新建processes文件夹放一个xxx.bpmn流程文件

    3. java config方式配置:config.activiti下新建一个类ActivitiConfig:

    其中数据源和事务管理器在3.spring boot mybatis druid多数据源里已经配置完,直接引用名字注入就可以了.

    package com.yunchuang.config.activiti;
    import org.activiti.spring.SpringAsyncExecutor;
    import org.activiti.spring.SpringProcessEngineConfiguration;
    import org.activiti.spring.boot.AbstractProcessEngineAutoConfiguration;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.transaction.PlatformTransactionManager;
    import javax.sql.DataSource;
    import java.io.IOException;
    /**
     * activiti配置文件
     * AbstractProcessEngineAutoConfiguration在activiti-spring-boot-starter-basic下
     *
     * @author 尹冬飞
     * @create 2017-04-10 10:30
     */
    @Configuration
    public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration {
        static final String NAME = "master";
        //注入数据源和事务管理器
        @Bean
        public SpringProcessEngineConfiguration springProcessEngineConfiguration(
                @Qualifier(NAME + "DataSource") DataSource dataSource,
                @Qualifier(NAME + "TransactionManager") PlatformTransactionManager transactionManager,
                SpringAsyncExecutor springAsyncExecutor) throws IOException {
            return this.baseSpringProcessEngineConfiguration(dataSource, transactionManager, springAsyncExecutor);
        }
    }
    

    4.这样就可以直接调用相关的service了.测试代码:

    package com.yunchuang;
    import org.activiti.engine.RuntimeService;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class Demo8ApplicationTests {
        @Autowired
        RuntimeService runtimeService;
        @Test
        public void contextLoads() {
            long count = runtimeService.createProcessInstanceQuery()
                    .count();
            System.out.println(count);
        }
    }
    

    相关文章

      网友评论

      • 醉江山_e162:我把activity包加进pom文件没有创建activity相关的类,启动程序报错Caused by: java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist
      • 59a29f9b572c:问一个问题 你这在用两个数据源和两个事务管理 ,你的业务处理和activiti任务完成如果放到一个service方法里面 事务没有统一, 业务出错事务回滚,activiti却不会回滚,怎么弄 我现在就碰到这个问题了?
      • 327988c324a5:请问能分享下源码么?
        会灰的大飞狼:没有demo的工程项目,你哪里不明白,可以问.
      • e0aa07bf3a18:请问resources目录下可以没有processes这个配置吗?我试了试报错,我想启动不自动加载,而是手动导入zip或者bpmn文件
        醉江山_e162:我把activity包加进pom文件没有创建activity相关的类,启动程序报错Caused by: java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist
        会灰的大飞狼:resources目录下processes目录下面可以不放流程文件,也可以在processes目录下新建文件夹,把流程文件放进去,这种情况下,是不会自动加载这个流程文件的,应该只加载processes目录下的流程文件.

      本文标题:4.spring boot activiti 整合

      本文链接:https://www.haomeiwen.com/subject/gvxuattx.html