Activiti工作流之spring整合

回顾:

Activiti工作流之简介与环境搭建

Activiti工作流之流程部署和相关操作

Activiti工作流之任务的运行/查询/完成

Activiti工作流之流程变量

Activiti工作流之历史查询

Activiti工作流之流程分支

Activiti工作流之网关

Activiti工作流之任务

新建一个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.spring.SpringProcessEngineConfiguration">
		<property name="dataSource" ref="dataSource"></property>
		<property name="transactionManager" ref="txManager"></property>
		<property name="databaseSchemaUpdate" value="true"></property>
	</bean>
	
	<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
		<property name="processEngineConfiguration" ref="processEngineConfiguration"></property>
	</bean>
	
	<!-- 
		获取服务接口的bean
	 -->
	<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"></bean>
	<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"></bean>
	<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"></bean>
</beans>

beans.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">

	<context:component-scan base-package="com.rl"/>
	<import resource="classpath:activiti.cfg.xml"/>
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
		<property name="url" value="jdbc:mysql://localhost:3306/activiti_spring"></property>
		<property name="username" value="root"></property>
		<property name="password" value="root"></property>
	</bean>
	
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	
	<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
</beans>

FlowService接口:

package com.rl.service;

public interface FlowService {

	public void deploy();
}

FlowServiceImpl实现类:

package com.rl.service.impl;

import org.activiti.engine.RepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rl.service.FlowService;
@Service
public class FlowServiceImpl implements FlowService {

	@Autowired
	RepositoryService repositoryService;
	
	@Override
	public void deploy() {

	}
}

测试代码:

package com.rl.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.rl.service.FlowService;

public class ActivitiTest {

	@Test
	public void test() {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
		FlowService fs = (FlowService) ctx.getBean("flowServiceImpl");
	}
}

或者

package com.rl.test;

import org.activiti.engine.RepositoryService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.rl.service.FlowService;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:beans.xml")
public class ActivitiTest1 {

	@Autowired
	RepositoryService repositoryService;
	
	@Autowired
	FlowService flowService;
	
	@Test
	public void test() {
		System.out.println(repositoryService);
		System.out.println(flowService);
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值