首页 > 代码库 > spring整合activiti

spring整合activiti

1.建立web项目,配置web.xml

     <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>            classpath*:/applicationContext.xml        </param-value>    </context-param>          <!-- 配置Spring的web监听器 -->    <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>        <!-- Struts2的拦截器 -->    <filter>        <filter-name>struts2</filter-name>76        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>    </filter>    <filter-mapping>        <filter-name>struts2</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>
View Code

2.配置application.xml

    <!-- 配置数据源的bean -->    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">        <property name="driverClass" value="com.mysql.jdbc.Driver" />        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/oa" />        <property name="user" value="root" />        <property name="password" value="root" />    </bean>    <!-- 配置Hibernate SessionFactory -->    <bean id="sessionFactory"        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">        <property name="dataSource" ref="dataSource"></property>        <!-- hibernate实体类注解 -->        <property name="packagesToScan">            <list>                <value>org.crazyit.activiti.oa.entity</value>            </list>        </property>        <property name="hibernateProperties">            <props>                <prop key="hibernate.hbm2ddl.auto">create</prop>                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>            </props>        </property>    </bean>    <!-- 配置事务管理 -->    <bean id="transactionManager"        class="org.springframework.orm.hibernate4.HibernateTransactionManager">        <property name="sessionFactory" ref="sessionFactory"></property>    </bean>    <!-- 事务拦截器 -->    <bean id="transactionInterceptor"        class="org.springframework.transaction.interceptor.TransactionInterceptor">        <property name="transactionManager" ref="transactionManager" />        <!-- 定义事务属性 -->        <property name="transactionAttributes">            <props>                <prop key="add*">PROPAGATION_REQUIRED</prop>                <prop key="create*">PROPAGATION_REQUIRED</prop>                <prop key="update*">PROPAGATION_REQUIRED</prop>                <prop key="insert*">PROPAGATION_REQUIRED</prop>            </props>        </property>    </bean>    <!-- 配置一个 BeanNameAutoProxyCreator, 实现根据bean名称自动创建事务代理 -->    <bean        class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">        <property name="beanNames">            <list>                <value>*Service</value>            </list>        </property>        <property name="interceptorNames">            <list>                <value>transactionInterceptor</value>            </list>        </property>    </bean>    <!-- Activiti的bean --><!-- 流程引擎的配置bean  -->    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">        <property name="dataSource" ref="dataSource" />        <property name="databaseSchemaUpdate" value="true"/>        <property name="transactionManager" ref="transactionManager" />    </bean>    <!-- 流程引擎的bean -->    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">        <property name="processEngineConfiguration" ref="processEngineConfiguration" />    </bean>    <!-- 服务组件的bean -->    <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="identityService" factory-bean="processEngine"        factory-method="getIdentityService" />    <bean id="managementService" factory-bean="processEngine"        factory-method="getManagementService" />
View Code

3.将struts.xml放置到根目录下,配置action

    <!-- 配置一个测试的Action -->    <package name="base" extends="struts-default">        <!-- 配置BaseAction -->        <action name="base" class="org.bestmyself.activiti.oa.action.BaseAction" method="test">            <result name="success">/pages/test.html</result>        </action>    </package>
View Code

4.编写测试用例,完成

spring整合activiti