久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術(shù)文章
文章詳情頁

Spring和activiti進行整合過程解析

瀏覽:79日期:2023-09-17 16:13:12

一、整合原理

activiti的配置文件本身就是一個spring的配置文件,但默認情況下只講ProcessEngineConfiguration作為一個bean來使用,調(diào)用ProcessEngines.getDefaultProcessEngine()加載的就是配置文件中的這個bean。和spring整合后就可以把bean的管理讓spring來進行,在代碼中獲取任意的bean。

activiti提供了一個spring模塊,在一個spring工程中引入這個模塊就能夠整合

<dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>5.22.0</version></dependency>

并且引入這個依賴后就不需要再單獨引入activiti的依賴了,這里邊已經(jīng)包含了

二、整合步驟

2.1 新建一個maven工程并導(dǎo)入相關(guān)依賴

<dependencies> <!--spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.0.2.RELEASE</version> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>5.22.0</version> </dependency> <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> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency></dependencies>

這里導(dǎo)入了spring,activiti,數(shù)據(jù)庫驅(qū)動等依賴。

2.2 創(chuàng)建spring配置文件

在resources目錄下創(chuàng)建spring配置文件,applicationContext.xml,其中主要配置如下bean

(1)數(shù)據(jù)源(連接池)

(2)事務(wù)管理器(和spring整合后必須配置事務(wù)管理器)

(3)流程引擎配置對象,這里可以注入一些流程引擎的配置

(4)流程引擎對象

(5)activiti的服務(wù)組件,配置后在程序中可以直接從容器中獲取

完整的配置文件如下

<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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd'> <!-- 配置連接池 --> <bean class='com.mchange.v2.c3p0.ComboPooledDataSource'> <property name='driverClass' value='com.mysql.jdbc.Driver'/> <property name='jdbcUrl' value='jdbc:mysql://localhost:3306/activiti_01'/> <property name='user' value='root'/> <property name='password' value='root'/> </bean> <!-- 事務(wù)管理器 --> <bean class='org.springframework.jdbc.datasource.DataSourceTransactionManager'> <property name='dataSource' ref='dataSource'></property> </bean> <!-- 配置使用spring提供的的流程引擎配置對象 --> <bean class='org.activiti.spring.SpringProcessEngineConfiguration'> <property name='dataSource' ref='dataSource'></property> <property name='transactionManager' ref='transactionManager'></property> <property name='databaseSchemaUpdate' value='true'></property> <property name='deploymentResources' value='classpath*:/process/*.bpmn'></property> </bean> <!-- 配置流程引擎工廠bean,獲取這個bean就可以直接獲取到流程引擎對象 --> <!-- 注意這個不是使用靜態(tài)工廠來獲取bean --> <bean class='org.activiti.spring.ProcessEngineFactoryBean'> <property name='processEngineConfiguration' ref='processEngineConfiguration'></property> </bean> <!-- 配置activiti的服務(wù)組件 --> <!-- 這里是通過實例工廠來創(chuàng)建服務(wù)組件的對象 ProcessEngine類的父類EngineServices中有獲取服務(wù)組件的get方法,所以這里把processEngine當做實例工廠來使用, 而這幾個對象是在創(chuàng)建流程引擎配置對象時就new出來的 --> <bean factory-bean='processEngine' factory-method='getRepositoryService'> </bean> <bean factory-bean='processEngine' factory-method='getRuntimeService'> </bean> <bean factory-bean='processEngine' factory-method='getTaskService'> </bean> <bean factory-bean='processEngine' factory-method='getHistoryService'> </bean></beans>

三、測試

在代碼中加載spring配置文件,并直接從容器里獲取服務(wù)組件,看能否直接使用服務(wù)組件

@Testpublic void test4() { ApplicationContext context = new ClassPathXmlApplicationContext('applicationContext.xml'); //通過容器獲取taskService組件 TaskService taskService= (TaskService) context.getBean('taskService'); System.out.println(taskService); List<Task> list = taskService.createTaskQuery().taskAssignee('tom').list(); for (Task task : list) { System.out.println(task); }}

如果能夠成功運行,說明activiti和spring已經(jīng)整合完成了。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 99精品欧美一区二区蜜桃免费 | 一本一道久久a久久精品综合蜜臀 | 老司机精品福利视频 | 亚洲视频在线免费观看 | 999国产一区二区三区四区 | 国产激情网 | 美女超碰| 国产91久久久久 | 久久精品视频免费观看 | 精品国产乱码久久久久久影片 | 日韩免费视频中文字幕 | 久久精品亚洲精品国产欧美kt∨ | 亚洲精品久久久久久久久久久 | 日韩高清av | 成人精品鲁一区一区二区 | 亚洲网站在线观看 | 精品久久久久久久久福利 | 夫妻午夜影院 | 国产成人精品一区二区三区四区 | 久久小视频 | 欧美喷潮久久久xxxxx | 性xxxxxxxxx18欧美 | 日本中文字幕在线视频 | 国产精品一区二区久久久 | 亚洲精品久久久 | 婷婷五月色综合香五月 | 丁香婷婷综合激情五月色 | 久久99国产精品 | 亚洲一区在线日韩在线深爱 | 粉嫩在线 | 日韩精品一 | 欧美日韩电影一区二区三区 | 99热少妇 | 理论片91 | 四虎影视 | 亚洲一区不卡在线 | 玖玖成人 | 成人国产在线 | 成人福利网站 | 午夜寂寞少妇aaa片毛片 | 成人在线观看一区 |