Activiti配置文件及pom依赖详解

1.pom依赖讲解

<!-- activiti 基础start -->
<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>
			</exclusions>
		</dependency>

		<!-- activiti 自带的web流程设计器 -->
		<dependency>
			<groupId>org.activiti</groupId>
			<artifactId>activiti-modeler</artifactId>
			<version>${activiti.version}</version>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.security</groupId>
					<artifactId>spring-security-config</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.springframework.security</groupId>
					<artifactId>spring-security-web</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

	<!-- activiti 配合上面的modeler -->
		<dependency>
			<groupId>org.activiti</groupId>
			<artifactId>activiti-diagram-rest</artifactId>
			<version>${activiti.version}</version>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.security</groupId>
					<artifactId>spring-security-config</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.springframework.security</groupId>
					<artifactId>spring-security-web</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

1629251154(1).png

1629251379(1).jpg

2.bootstrap.yml配置讲解

server:
  port: 5005

spring:
  application:
    name: @artifactId@
  cloud:
    nacos:
      discovery:
        server-addr: ${NACOS_HOST:air-register}:${NACOS_PORT:8848}
      config:
        server-addr: ${spring.cloud.nacos.discovery.server-addr}
        file-extension: yml
        shared-configs:
          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
  profiles:
    active: @profiles.active@
  activiti:
    check-process-definitions: false #是否自动部署
    database-schema-update: true #activiti建表策略
    async-executor-activate: false #异步作业执行器是否要开启 默认不开启
    async-executor-enabled: false #和上面意思差不多
    job-executor-activate: false #同步作业执行器是否开启
    jpa-enabled: false #jpa开启

#开启activiti打印日志,还需要在logback-spring.xml开启
logging:
  level:
    org.activiti.engine.impl.persistence.entity: trace

3.logback-spring.xml

开启activiti打印日志,还需要在logback-spring.xml开启

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~    Copyright (c) 2018-2025, air All rights reserved.
  ~
  ~ Redistribution and use in source and binary forms, with or without
  ~ modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~ this list of conditions and the following disclaimer.
  ~ Redistributions in binary form must reproduce the above copyright
  ~ notice, this list of conditions and the following disclaimer in the
  ~ documentation and/or other materials provided with the distribution.
  ~ Neither the name of the pig4cloud.com developer nor the names of its
  ~ contributors may be used to endorse or promote products derived from
  ~ this software without specific prior written permission.
  ~ Author: air
  -->

<!--
    小技巧: 在根pom里面设置统一存放路径,统一管理方便维护
    <properties>
        <log-path>/Users/air</log-path>
    </properties>
    1. 其他模块加日志输出,直接copy本文件放在resources 目录即可
    2. 注意修改 <property name="${log-path}/log.path" value=""/> 的value模块
-->
<configuration debug="false" scan="false">
	<property name="log.path" value="logs/${project.artifactId}"/>
	<!-- 彩色日志格式 -->
	<property name="CONSOLE_LOG_PATTERN"
			  value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
	<!-- 彩色日志依赖的渲染类 -->
	<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
	<conversionRule conversionWord="wex"
					converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
	<conversionRule conversionWord="wEx"
					converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
	<!-- Console log output -->
	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>${CONSOLE_LOG_PATTERN}</pattern>
		</encoder>
	</appender>

	<!-- Log file debug output -->
	<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${log.path}/debug.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
			<maxFileSize>50MB</maxFileSize>
			<maxHistory>30</maxHistory>
		</rollingPolicy>
		<encoder>
			<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
		</encoder>
	</appender>

	<!-- Log file error output -->
	<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${log.path}/error.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
			<maxFileSize>50MB</maxFileSize>
			<maxHistory>30</maxHistory>
		</rollingPolicy>
		<encoder>
			<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
		</encoder>
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>ERROR</level>
		</filter>
	</appender>

  <!-- 开启日志-->
	<logger name="org.activiti.engine.impl.db" level="DEBUG">
		<appender-ref ref="debug"/>
	</logger>

	<!-- 开启日志-->
	<logger name="org.activiti.engine.impl.persistence.entity" level="trace">
		<appender-ref ref="console" />
	</logger>

	<!--nacos 心跳 INFO 屏蔽-->
	<logger name="com.alibaba.nacos" level="OFF">
		<appender-ref ref="error"/>
	</logger>
	<!-- Level: FATAL 0  ERROR 3  WARN 4  INFO 6  DEBUG 7 -->
	<root level="INFO">
		<appender-ref ref="console"/>
		<appender-ref ref="debug"/>
	</root>
</configuration>

4.config配置类讲解

/*
 *    Copyright (c) 2018-2025, air All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: air
 */

package com.pofly.air.act.config;

import lombok.AllArgsConstructor;
import org.activiti.engine.impl.history.HistoryLevel;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

/**
 * @author pxz
 * @date 2021/8/18 Activiti 配置
 */
@Configuration
@AllArgsConstructor
public class ActivitiConfig {

	private final DataSource dataSource;

	private final PlatformTransactionManager transactionManager;

	@Bean
	public SpringProcessEngineConfiguration getProcessEngineConfiguration() {
		SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();

		//初级配置
		config.setActivityFontName("宋体"); //设置字体
		config.setAnnotationFontName("宋体");
		config.setLabelFontName("黑体"); //设置连线字体
		config.setDataSource(dataSource); //设置数据源
		config.setTransactionManager(transactionManager); //设置事务管理器
		config.setDatabaseType("mysql"); //设置数据库类型 主要是为了屏蔽SQL语句差异问题
		config.setDatabaseSchemaUpdate("true"); //设置建表策略
		config.setDatabaseSchemaUpdate("true"); //设置DB建表策略
		config.setHistoryLevel(HistoryLevel.AUDIT); //设置DB历史数据级别
		
		return config;
	}

	@Bean
	@Primary
	public TaskExecutor primaryTaskExecutor() {
		return new ThreadPoolTaskExecutor();
	}

}

4.1 databaseSchemaUpdate

关于数据库的数据库表生成策略

false:默认值,流程引擎启动时,首先从ACT_GE_BTEARRAY表中查询Activiti的版本值(schema.version)然后获取ProcessEngine接口中定义的VERSION静态变量值,两者进行对比,如果DB中的表不存在或者不匹配直接抛异常

true:流程引擎启动时会对所有表进行更新操作,(upgrade目录中的DDL脚本,如果DV中的表不存在,则开始创建表create目录中的DDL脚本)

create_drop: 流程引擎启动时创建表,关闭时删除表

drop_create: 流程引擎启动时,首先删除DB中存在的表,然后重新创建表

create:流程引擎启动时直接创建表,不管DB中是否存在

4.2historyLevel

历史级别

none:所有的历史归档数据不进行入库记录,因此该级别对于流程实例运转涞水性能最高,但是由于不涉及历史表的操作,客户端一旦配置该级别,则无法查询流程实例的运转轨迹及细节信息,因此强烈不推荐

actitity:归档所有的流程实例以及活动实例,不归档流程细节,例如历史人物节点

audit:默认级别,归档所有流程实例,活动实例以及提交的表单属性,所有与用户交互的数据(表单)都是可以进行跟踪并且统计的

full:最高级别,记录所有的历史数据,因此流程实例运转也是最慢的,该级别除了保留audit级别所有的信息之外还要保存类似流程变量以及其他可能需要的历史数据

备注:流程变量存在ACT_RU_VARTABLE中开启了full级别后流程变量还会存在ACT_HI_DETALL

移入语雀里面更加详细

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值