SpringCloud整合Activiti 实战 (一)

新入职的公司需要自己开发一套工作流的项目,以前虽然接触过Activiti工作流引擎,但是接触不深,只停留在使用阶段,没有做深入的了解。借这次机会,搭建一套工作流引擎框架。

技术选型

SpringCloud + Activiti

Activiti 版本为5.22 ,因为网上关于Activiti,使用最多的是5.22版本。。。SpringBoot 版本为2.1.15,SpringCloud 版本为 Greenwich.SR3,下面附上maven依赖:

<dependencies>
	<dependency>
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
	</dependency>
	<dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-spring-boot-starter-basic</artifactId>
        <version>${activiti.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
            </exclusion>
            <exclusion>
                <artifactId>activation</artifactId>
                <groupId>javax.activation</groupId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-diagram-rest</artifactId>
        <version>${activiti.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-security-config</artifactId>
                <groupId>org.springframework.security</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-security-core</artifactId>
                <groupId>org.springframework.security</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-security-crypto</artifactId>
                <groupId>org.springframework.security</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-security-web</artifactId>
                <groupId>org.springframework.security</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-modeler</artifactId>
        <version>${activiti.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-security-config</artifactId>
                <groupId>org.springframework.security</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-security-core</artifactId>
                <groupId>org.springframework.security</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-security-crypto</artifactId>
                <groupId>org.springframework.security</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-security-web</artifactId>
                <groupId>org.springframework.security</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

	<dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
	<dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.1.20</version>
    </dependency>
</dependencies>

中间activiti依赖排除security相关依赖,是为了解决后面访问需要登录的问题。
配置文件如下:

server:
  port: 8081
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://你的数据库连接
    username: 你的数据库用户名
    password: 你的数据库密码
    druid:
      max-active: 20
      max-wait: 5000
      initial-size: 1
      filters: stat,log4j,wall
  activiti:
  	# 这条配置为true,会默认加在resources/processes包下的流程文件(.bpmn),如果刘成文件没有会导致项目启动报错,所以设置为false
    check-process-definitions: false
    database-schema: ACTIVITI
    # 设置为true,如果库中没有activiti对应表,就创建
    database-schema-update: true
    history-level: audit
    db-history-used: true
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
logging:
  level:
    com.puren: info
mybatis:
  # 这里需要注意,如果resources下结构是mapping下放的mapper.xml,则如下,否则需要把完整的匹配目录不全,如:resources/xxx/xxx.xml,则需要匹配为classpath*:mapping/**/*.xml
  mapper-locations: classpath*:mapping/*.xml
  type-aliases-package: com.xxxx.*

启动类如下:

@SpringBootApplication(exclude = {
        org.activiti.spring.boot.SecurityAutoConfiguration.class,
        org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
})
@EnableDiscoveryClient
@MapperScan(basePackages = "com.xxxx")
public class OaApplication {
    public static void main(String[] args) {
        SpringApplication.run(OaApplication.class, args);
    }
}

启动后可在数据库中看到已经生成了25张表

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值