最近因公司的业务需求,需要使用工作流来做我们业务中的流程审批工作,so 就安排我做了这个工作,发现整合的时候有一些问题,及时的记录下来分享给大家。
介绍:
一、如果你的web项目只是单纯的web项目那么只需要将对应的jar包放到lib下构建一下即可
二、如果你的web项目是maven项目那么这里就需要在pom.
1、在pom.
<dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>5.18.0</version> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>5.18.0</version> </dependency>
2、需要在src下加一个activiti-context.
<? ="http://www.springframework.org/schema/context" ="http://www.springframework.org/schema/tx" ="http://www.w3.org/2001/ 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 id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean><!-- spring负责创建流程引擎的配置文件 --> <bean id="processEngineConfiguration" class="cn.com.sinosoft.workflow.service.MySpringProcessEngineConfiguration"> <!-- 数据源 --> <property name="dataSource1" ref="dataSource" /> <!-- 配置事务管理器,统一事务 --> <property name="transactionManager" ref="transactionManager" /> </bean> <!-- 创建流程引擎对象 --> <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"> <property name="processEngineConfiguration" ref="processEngineConfiguration" /> </bean> <!-- 相当于下面的代码 RepositoryServicie repositoryService = processEngine.getRepositoryService(); RuntimeServicie repositoryService = processEngine.getRuntimeServicie(); TaskServicie taskServicie = processEngine.getTaskServicie(); HistoryServicie historyServicie = processEngine.getHistoryServicie(); --> <!-- 由流程引擎对象,提供的方法,创建项目中使用的Activiti工作流的Service --> <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" /> <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" /> <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" /> <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" /> <bean id="formService" factory-bean="processEngine" factory-method="getFormService" /></beans>
3、需要在web.
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:applicationContext*.*:/applicationContext*./WEB-INF/applicationContext*.*:**/applicationContext*.-context.</param-value> </context-param>
4、以上配置成功的话其实就可以使用了,但是只要细心观察的话就会发现一点在activiti-context.
@Override public ProcessEngineConfiguration setDataSource(DataSource dataSource) { if (dataSource instanceof TransactionAwareDataSourceProxy) { return super.setDataSource(dataSource); } else { // Wrap datasource in Transaction-aware proxy DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource); return super.setDataSource(proxiedDataSource); } }
发现这个官方给的类中setDataSource方法竟然有返回值,那么我初步的想法就是可能是根据反射这块出问题了,为此我就开始想对策,正常的set方法时没有返回值的,也许可能就是因为这块调用的是有返回值的方法所以出的错误,那么我就自己写个类,去继承这个官网给出的类,然后配置的时候调用我自己写的类这样就解决了我的问题,有了想法后开始实践
package cn.com.sinosoft.workflow.service;import javax.sql.DataSource;public class MySpringProcessEngineConfiguration extends org.activiti.spring.SpringProcessEngineConfiguration{ public void setDataSource1(DataSource dataSource1) { super.setDataSource(dataSource1); }}
在activiti-context.
原标题:activiti和SSH项目做整合
关键词:SSH