activiti与spring集成(maven)

来源:互联网 发布:js实现的简单的小特效 编辑:程序博客网 时间:2024/06/04 20:45

在pom.xml中添加以下依赖:

[java] view plaincopy在CODE上查看代码片派生到我的代码片
  1. <dependency>  
  2.     <groupId>org.activiti</groupId>  
  3.     <artifactId>activiti-engine</artifactId>  
  4.     <version>${activiti.version}</version>  
  5. </dependency>  
  6.   
  7. <dependency>  
  8.     <groupId>org.activiti</groupId>  
  9.     <artifactId>activiti-spring</artifactId>  
  10.     <version>${activiti.version}</version>  
  11. </dependency>  

        此处忽略了spring的依赖,请自行配置。

        在src下添加spring-activiti.xml文件,内容如下:

[java] view plaincopy在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"  
  4.     xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"  
  5.     xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"  
  6.     xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jpa="http://www.springframework.org/schema/data/jpa"  
  7.     xmlns:tool="http://www.springframework.org/schema/tool" xmlns:context="http://www.springframework.org/schema/context"  
  8.     xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
  9.     xsi:schemaLocation="http://www.springframework.org/schema/beans    
  10.      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
  11.      http://www.springframework.org/schema/tx    
  12.      http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
  13.      http://www.springframework.org/schema/aop    
  14.      http://www.springframework.org/schema/aop/spring-aop.xsd    
  15.      http://www.springframework.org/schema/jee    
  16.      http://www.springframework.org/schema/jee/spring-jee.xsd    
  17.      http://www.springframework.org/schema/context    
  18.      http://www.springframework.org/schema/context/spring-context.xsd    
  19.      http://www.springframework.org/schema/cache  
  20.      http://www.springframework.org/schema/cache/spring-cache-3.1.xsd  
  21.      http://www.springframework.org/schema/data/jpa  
  22.      http://www.springframework.org/schema/data/jpa/spring-jpa.xsd  
  23.      http://www.springframework.org/schema/util    
  24.      http://www.springframework.org/schema/util/spring-util-3.1.xsd  
  25.      http://www.springframework.org/schema/jdbc   
  26.      http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd  
  27.      http://www.springframework.org/schema/tool    
  28.      http://www.springframework.org/schema/tool/spring-tool.xsd"  
  29.     default-lazy-init="true" >  
  30.   
  31.     <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">  
  32.         <property name="dataSource" ref="${jpa.datasource.name}" />  
  33.         <property name="transactionManager" ref="transactionManager" />  
  34.         <property name="databaseSchemaUpdate" value="true" />  
  35.         <property name="jpaEntityManagerFactory" ref="entityManagerFactory" />  
  36.         <property name="jpaHandleTransaction" value="true" />  
  37.         <property name="jpaCloseEntityManager" value="true" />  
  38.         <property name="jobExecutorActivate" value="false" />  
  39.         <!-- 使用spring的自动资源加载部署方式部署 -->  
  40.         <property name="deploymentResources" value="classpath*:diagrams/*.*" />  
  41.     </bean>  
  42.   
  43.     <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">  
  44.         <property name="processEngineConfiguration" ref="processEngineConfiguration" />  
  45.     </bean>  
  46.   
  47.     <bean id="identityService" factory-bean="processEngine"  
  48.         factory-method="getIdentityService" />  
  49.     <bean id="formService" factory-bean="processEngine"  
  50.         factory-method="getFormService" />  
  51.     <bean id="repositoryService" factory-bean="processEngine"  
  52.         factory-method="getRepositoryService" />  
  53.     <bean id="runtimeService" factory-bean="processEngine"  
  54.         factory-method="getRuntimeService" />  
  55.     <bean id="taskService" factory-bean="processEngine"  
  56.         factory-method="getTaskService" />  
  57.     <bean id="historyService" factory-bean="processEngine"  
  58.         factory-method="getHistoryService" />  
  59.     <bean id="managementService" factory-bean="processEngine"  
  60.         factory-method="getManagementService" />  
  61.   
  62.   
  63.   
  64. </beans>   

        注意:

        1. 不要使用default-autowire="byName",否则会报空指针异常;

        2. dataSource、transactionManager、jpaEntityManagerFactory请自行配置;

        3. ${jpa.datasource.name}为配置文件中的项,请查询资料自行配置;

        4. deploymentResources配置的是流程文件所在位置,本文中为src的diagrams目录下的所有。


0 0
原创粉丝点击