企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**1. 请先准备好如下环境** JDK1.8+、MySQL5+、IntelliJ IDEA或者Eclipse。 **2. IDEA中安装Activiti流程设计器** :-: ![](https://img.kancloud.cn/a5/f9/a5f93df868681af620606279a4f0ddc8_647x369.png) 如果IDEA中找不到 actiBPM 插件,可以如下安装: (1)下载actiBPM的JAR包。 地址:[https://plugins.jetbrains.com/](https://plugins.jetbrains.com/) ![](https://img.kancloud.cn/f5/d2/f5d2b953ba643f8f75d259a13da31428_1621x351.png) ![](https://img.kancloud.cn/80/af/80af06744daeec69dd0a4ec62b3eb62b_1806x646.png) (2)在IDEA中选择从磁盘中导入该JAR包,选择下载的actibpm.jar包。 ![](https://img.kancloud.cn/cf/04/cf04f26bea904e2287ab31a31194d7c2_1231x379.png) (3)重启IDEA即可。 **3. 创建一个maven项目,`pom.xml`如下** ```xml <!-- activiti 的相关包 mysql的驱动包 mybatis log4j 数据库链接池--> <properties> <slf4j.version>1.6.6</slf4j.version> <log4j.version>1.2.12</log4j.version> <activiti.version>7.0.0.Beta1</activiti.version> </properties> <dependencies> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>${activiti.version}</version> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>${activiti.version}</version> </dependency> <!-- bpmn 模型处理 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-bpmn-model</artifactId> <version>${activiti.version}</version> </dependency> <!-- bpmn 转换 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-bpmn-converter</artifactId> <version>${activiti.version}</version> </dependency> <!-- bpmn json数据转换 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-json-converter</artifactId> <version>${activiti.version}</version> </dependency> <!-- bpmn 布局 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-bpmn-layout</artifactId> <version>${activiti.version}</version> </dependency> <!-- activiti 云支持 --> <dependency> <groupId>org.activiti.cloud</groupId> <artifactId>activiti-cloud-services-api</artifactId> <version>${activiti.version}</version> </dependency> <!-- mysql驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.40</version> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.5</version> </dependency> <!-- 链接池 --> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <!-- log start --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.6</version> </dependency> </dependencies> ``` **4. log4j日志配置文件`resources/log4j.properties`** ```properties # Set root category priority to INFO and its only appender to CONSOLE. #log4j.rootCategory=INFO, CONSOLE debug info warn error fatal log4j.rootCategory=debug, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r[%15.15t] %-5p %30.30c %x - %m\n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=f:\act\activiti.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r[%15.15t] %-5p %30.30c %x - %m\n ``` **5. 配置ProcessEngineConfiguration** * 配置方式1 *`resources/activiti.cfg.xml`* ```xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/contex http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 默认id对应的值 为processEngineConfiguration --> <!-- processEngine Activiti的流程引擎 --> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcDriver" value="com.mysql.jdbc.Driver"/> <property name="jdbcUrl" value="jdbc:mysql://localhost/activiti?useUnicode=true&amp;characterEncoding=UTF-8"/> <property name="jdbcUsername" value="root"/> <property name="jdbcPassword" value="123456"/> <!-- activiti数据库表处理策略 true:表已经存在则使用,没有则创建--> <property name="databaseSchemaUpdate" value="true"/> </bean> </beans> ``` * 配置方式2 *`resources/activiti.cfg.xml`* ```xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/contex http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 这里可以使用 链接池 dbcp--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost/activiti?useUnicode=true&amp;characterEncoding=UTF-8" /> <property name="username" value="root" /> <property name="password" value="123456" /> <property name="maxActive" value="3" /> <property name="maxIdle" value="1" /> </bean> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <!-- 引用数据源 上面已经设置好了--> <property name="dataSource" ref="dataSource" /> <!-- activiti数据库表处理策略 --> <property name="databaseSchemaUpdate" value="true"/> </bean> </beans> ``` **6. 生成相关表** 先在MySQL中创建activiti数据库,然后用下面的程序自动生产相关的表。 ```java public class TestCreate { @Test public void testCreateDbTable() { // 创建方式1:采用Activiti默认方式建表 // 方法getDefaultProcessEngine会默认从resources下读取名字为actviti.cfg.xml的文件 // 创建processEngine时,就会创建mysql的表 ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); } } ``` **7. 运行上面的程序就会自动生成如下25张表** ![](https://img.kancloud.cn/cc/e7/cce719014395ddfc00ea06c4413e4f3e_1365x346.png)