您好,登錄后才能下訂單哦!
文章源碼托管:https://github.com/OUYANGSIHAI/Activiti-learninig
歡迎 star ?。。?/p>
在上一節(jié)中我們對(duì)activiti進(jìn)行了基本的介紹activiti進(jìn)行了基本的介紹,同時(shí)介紹了基本的概念。
這一節(jié),我將用一個(gè)入門程序,介紹如何使用activiti。
這里我們使用Idea
進(jìn)行工作流開發(fā),雖然Idea對(duì)于工作流的友好度不是很好,因?yàn)闀?huì)有一些小的bug,但是,Idea對(duì)于Java的開發(fā)還是非常的好的。
在用Idea開發(fā)之前,我們需要在idea中安裝bpmn開發(fā)的插件。方法如下
打開設(shè)置
選擇plugins
搜索actiBPM
重啟idea,新建文件
如果能夠找到下面的創(chuàng)建方法,就代表成功了。
新建后出現(xiàn)下面的編輯頁面
到現(xiàn)在,bpmn編輯插件就準(zhǔn)備好了。
新建的maven項(xiàng)目目錄如下
這里需要的pom依賴有以下幾個(gè):junit、druid、mysql、lombok(日志)、activiti
<?xml version="1.0" encoding="UTF-8"?>
<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.sihai</groupId>
<artifactId>acitvitiDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.12</version>
</dependency>
<!-- logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.22</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.22.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<!--<appender name="permission" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!--<file>${catalina.home}/logs/permission.log</file>-->
<!--<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!--<FileNamePattern>${catalina.home}/logs/permission.%d{yyyy-MM-dd}.log.gz</FileNamePattern>-->
<!--</rollingPolicy>-->
<!--<layout class="ch.qos.logback.classic.PatternLayout">-->
<!--<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>-->
<!--</layout>-->
<!--</appender>-->
<!---->
<!--<logger name="xxx" level="INFO">-->
<!--<appender-ref ref="permission"/>-->
<!--</logger>-->
<!-- TRACE < DEBUG < INFO < WARN < ERROR -->
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
下面是添加一個(gè)junit測(cè)試實(shí)例,通過測(cè)試生成activiti底層需要的數(shù)據(jù)庫表,總共有25張,如果數(shù)據(jù)庫生成了25張表結(jié)構(gòu),則說明成功!
/**
* @Author ouyangsihai
* @Description 生成activiti底層數(shù)據(jù)庫表結(jié)構(gòu)
* @Date 16:24 2019/1/26
* @Param
* @return
**/
public class Activiti_01 {
/**
* @return void
* @Author ouyangsihai
* @Description //生成數(shù)據(jù)庫表結(jié)構(gòu)
* @Date 20:57 2018/12/5
* @Param []
**/
@Test
public void test_createDatabase() {
// 創(chuàng)建流程引擎配置信息對(duì)象
ProcessEngineConfiguration pec = ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration();
// 設(shè)置數(shù)據(jù)庫的類型
pec.setDatabaseType("mysql");
// 設(shè)置創(chuàng)建數(shù)據(jù)庫的方式
// ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE(true);//如果沒有數(shù)據(jù)庫表就會(huì)創(chuàng)建數(shù)據(jù)庫表,有的話就修改表結(jié)構(gòu).
// ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE(false): 不會(huì)創(chuàng)建數(shù)據(jù)庫表
// ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP(create-drop): 先創(chuàng)建、再刪除.
pec.setDatabaseSchemaUpdate("true");
// 設(shè)置數(shù)據(jù)庫驅(qū)動(dòng)
pec.setJdbcDriver("com.mysql.jdbc.Driver");
// 設(shè)置jdbcURL
pec.setJdbcUrl("jdbc:mysql://localhost:3306/activitiTest?useUnicode=true&characterEncoding=UTF-8");
// 設(shè)置用戶名
pec.setJdbcUsername("root");
// 設(shè)置密碼
pec.setJdbcPassword("root");
pec.setJdbcPassword("XXXX");
// 構(gòu)建流程引擎對(duì)象
ProcessEngine pe = pec.buildProcessEngine(); // 調(diào)用訪方法才會(huì)創(chuàng)建數(shù)據(jù)表
// 調(diào)用close方法時(shí),才會(huì)刪除
pe.close();
}
}
運(yùn)行上面的測(cè)試實(shí)例后,將會(huì)生成下面的25張表結(jié)構(gòu)。
日志信息
表結(jié)構(gòu)
通過上面是入門實(shí)例,就將activiti的環(huán)境準(zhǔn)備好了!
文章有不當(dāng)之處,歡迎指正,如果喜歡微信閱讀,你也可以關(guān)注我的微信公眾號(hào):
好好學(xué)java
,獲取優(yōu)質(zhì)學(xué)習(xí)資源。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。