To create a maven project, the pom configuration of the required jar is as follows:
(Each dependency has a dependency copy address above)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.xiaoyexinxixn</groupId> <artifactId>ActivityLesson</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>ActivityLesson</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- https://mvnrepository.com/artifact/org.activiti/activiti-engine --> <!-- activity workflow engine--> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>5.17.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.activiti/activiti-spring --> <!-- The jar package of activiti-spring combined with spring--> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>5.17.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.activiti/activiti-bpmn-model --> <!-- bpmn model package--> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-bpmn-model</artifactId> <version>5.17.0</version> </dependency> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <!-- link database --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.17</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
Let's write a test class that connects to the database, build the 24 tables needed by the activity, and first build a database:
Code:
package com.xiaoyexinxixn.ActivityLesson; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngineConfiguration; import org.junit.Test; public class ActivityConnectionDB { /* * 25 tables of production database activity */ @Test public void CreateTabel(){ //Get the process engine configuration ProcessEngineConfiguration pec=ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration(); //Load mysql driver pec.setJdbcDriver("com.mysql.jdbc.Driver"); // link database pec.setJdbcUrl("jdbc:mysql://localhost:3306/db_activity"); //Set the connection mysql user pec.setJdbcUsername("root"); //Set the link mysql password pec.setJdbcPassword("123456"); //Set the automatic creation table and update table pec.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); //Build the process engine, that is, get the process engine object ProcessEngine pe=pec.buildProcessEngine(); } }
As can be seen from the code, the activity engine will automatically build 24 tables.
24 tables produced in the database:
The function of each table will not be introduced, readers can Baidu;
Next, we change the way of linking the database to the configuration file format. The content of xml can be copied on the activiti official website, the address:
https://www.activiti.org/userguide/index.html#_configuration
Let's create an activiti.cfg.xml file in the following figure, and the file name must be strictly defined as this name:
Here we do the simplest configuration first:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <!-- Database configurations --> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/db_activity" /> <property name="jdbcDriver" value="com.mysql.jdbc.Driver" /> <property name="jdbcUsername" value="root" /> <property name="jdbcPassword" value="123456" /> <property name="databaseSchemaUpdate" value="true" /> </bean> </beans>
Test code:
/* * Get the process engine object through the configuration file */ @Test public void createTableWithXML(){ //engine configuration ProcessEngineConfiguration pec=ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml"); //Get the process engine object pec.buildProcessEngine(); }
Here we first delete the previously built table, and then run the above test code;
Next, we want to download the plug-in for drawing activity workflow diagram on eclipse
help-->Install help software
Click the add button and enter:
name: Activiti BPMN 2.0 designer
location: http://activiti.org/designer/update/