大家好,又见面了,我是你们的朋友全栈君。
一直没有更新最近,把以前的资料整理下。 SSH的集成配置清查看上一篇
struts-2.3.24+spring-framework-4.1.6.RELEASE+hibernate-release-4.3.10.Final 集成开发
导入activity工作流需要的jar activiti-bpmn-converter-5.16.4.jar activiti-bpmn-layout-5.16.4.jar activiti-bpmn-model-5.16.4.jar activiti-camel-5.16.4.jar activiti-cdi.jar activiti-common-rest-5.16.4.jar activiti-crystalball-5.16.4.jar activiti-cxf-5.16.4.jar activiti-diagram-rest-5.16.4.jar activiti-engine-5.16.4.jar activiti-explorer-5.16.4.jar activiti-image-generator-5.16.4.jar activiti-json-converter-5.16.4.jar activiti-ldap-5.16.4.jar activiti-modeler-5.16.4.jar activiti-mule-5.16.4.jar activiti-osgi-5.16.4.jar activiti-process-validation-5.16.4.jar activiti-simple-workflow-5.16.4.jar activiti-rest-5.16.4.jar activiti-spring-5.16.4.jar
添加配置文件:新建activiti.cfg.xml文件
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- spring负责创建流程引擎的配置文件 -->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 配置事务管理器,统一事务 -->
<property name="transactionManager" ref="txManager" />
<!-- 设置建表策略,如果没有表,自动创建表 -->
<property name="databaseSchemaUpdate" value="true" />
</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>
到此配置完成使用的时候可使用注解注入activity的
//获取流程引擎对象,通过流程引擎对象可以获取其他几个服务对象
@Resource
private ProcessEngine processEngine;
//获取部署流程对象服务,通过repositoryService可以部署流程信息,查询流程信息
@Resource
private RepositoryService repositoryService;
//获取流程运行时对象,可通过查询正在执行中的流程信息
@Resource
private RuntimeService runtimeService;
//任务服务对象,可通过他查询任务信息
@Resource
private TaskService taskService;
//历史服务对象,通过他查询历史流程信息
@Resource
private HistoryService historyService;
通过
<import resource="classpath:activiti.cfg.xml" />
导入到applicationContext.xml配置文件,交给spring管理。详细查看applicationContext.xml配置。
接下来是activity的基本使用。
如下配置applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 1、自动扫描与装配bean -->
<context:component-scan base-package="cn.ssha"></context:component-scan>
<!-- 导入外部的配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<!-- 其他配置 -->
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize" value="3"></property>
<!--连接池中保留的最小连接数。Default: 3 -->
<property name="minPoolSize" value="3"></property>
<!--连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize" value="5"></property>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="3"></property>
<!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
<property name="maxStatements" value="8"></property>
<!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
<property name="maxStatementsPerConnection" value="5"></property>
<!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="1800"></property>
</bean>
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 指定hibernate的配置路径 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<property name="dataSource" ref="dataSource"></property>
<!-- 配置c3p0数据库连接池 <property name="dataSource"> <bean class="com.mchange.v2.c3p0.ComboPooledDataSource"> 数据库连接信息 <property name="jdbcUrl" value="${jdbcUrl}"></property> <property name="driverClass" value="${driverClass}"></property> <property name="user" value="${user}"></property> <property name="password" value="${password}"></property> 其他配置 初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 <property name="initialPoolSize" value="3"></property> 连接池中保留的最小连接数。Default: 3 <property name="minPoolSize" value="3"></property> 连接池中保留的最大连接数。Default: 15 <property name="maxPoolSize" value="5"></property> 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 <property name="acquireIncrement" value="3"></property> 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 <property name="maxStatements" value="8"></property> maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 <property name="maxStatementsPerConnection" value="5"></property> 最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 <property name="maxIdleTime" value="1800"></property> </bean> </property> -->
<!-- <property name="mappingResources"> <list> <value>cn/ssha/oa/doman/Product.hbm.xml</value> <value>cn/ssha/oa/doman/Employee.hbm.xml</value> <value>cn/ssha/oa/doman/LeaveBill.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect hibernate.show_sql=true hibernate.hbm2ddl.auto=update hibernate.temp.use_jdbc_metadata_defaults=false </value> </property> -->
</bean>
<!-- 配置声名式事务管理(采用注解的方式) -->
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<!-- 配置基础的Dao,在其他的DAO中只需要继承即可 -->
<bean id="baseDao" abstract="true">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<import resource="classpath:activiti.cfg.xml" />
</beans>
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/144877.html原文链接:https://javaforall.cn