Activiti開發環境的搭建過程詳解
阿新 • • 發佈:2020-03-10
本文中使用maven+eclipse搭建activiti-5.14的開發環境
一、建立maven工程
建立一個普通的java工程,pom檔案的內容如下
<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.lyy</groupId> <artifactId>activtiviti-study-01</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>5.14</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.26</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.2</version> <type>jar</type> <scope>compile</scope> </dependency> </dependencies> </project>
二、新增activiti的配置檔案
在工程的resources目錄下建立activiti的配置檔案,名稱為activiti.cfg.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" 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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 配置使用預設bean名稱的流程引擎配置物件 --> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti_01"></property> <property name="jdbcUsername" value="root"></property> <property name="jdbcPassword" value="root"></property> <property name="databaseSchemaUpdate" value="true"></property> </bean> </beans>
三、測試
新建一個測試類,新增如下程式碼,
public class Test1 { /** * 測試環境是否可用 */ @Test public void test1() { ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault(); System.out.println(configuration); } }
執行測試方法test1,如果正常執行,並輸出ProcessEngineConfiguration物件的地址,則表示開發環境搭建成功。
四、總結
用maven搭建activiti的開發環境,需要先引入activiti的依賴
<dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>5.14</version> </dependency>
因為要操作資料庫,所以需要引入msql的驅動和資料庫連線池
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.26</version> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.2</version> <type>jar</type> <scope>compile</scope> </dependency>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。