复习步骤31-整合框架(1)整合Spring--web

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiangshuai198807/article/details/90199763

  整合框架(2)web项目整合Activiti

使用技术

  • Maven
  • Spring
  • Struts
  • Hibernate

项目结构

 

 

 

 

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:context="http://www.springframework.org/schema/context"

    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"

    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.xsd

       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd

       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">

 

    <!-- 配置数据源的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/ACT" />

        <property name="user" value="SSS" />

        <property name="password" value="SSS" />

    </bean>

 

    <!-- 配置Hibernate SessionFactory -->

    <bean id="sessionFactory"

        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">

        <property name="dataSource" ref="dataSource"></property>

        <property name="mappingResources">

            <list>

                <value>Person.hbm.xml</value>

            </list>

        </property>

        <property name="hibernateProperties">

            <props>

                <prop key="hibernate.hbm2ddl.auto">update</prop>

                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect

                </prop>

            </props>

        </property>

    </bean>

    <!-- 配置事务管理 -->

    <bean id="transactionManager"

        class="org.springframework.orm.hibernate5.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="*">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>

 

    <!-- Activitibean -->

    <!-- 流程引擎的配置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="managementService" factory-bean="processEngine"

        factory-method="getManagementService" />

 

 

    <bean id="testAction" class="org.crazyit.act.aw.action.TestAction">

        <property name="personService" ref="personService"></property>

        <property name="taskService" ref="taskService"></property>

    </bean>

 

    <bean id="personDao" class="org.crazyit.act.aw.dao.impl.PersonDaoImpl">

        <property name="sessionFactory" ref="sessionFactory"></property>

    </bean>

 

    <bean id="personService" class="org.crazyit.act.aw.service.impl.PersonServiceImpl">

        <property name="personDao" ref="personDao"></property>

    </bean>

 

</beans>

 

测试方法

package org.crazyit.act.aw.action;

 

import java.util.List;

 

import org.activiti.engine.TaskService;

import org.crazyit.act.aw.entity.Person;

import org.crazyit.act.aw.service.PersonService;

 

import com.opensymphony.xwork2.Action;

 

/**

 * @author lqx

 *  文件在 E:\学习文档子目录压缩\框架\工作流引擎\Activiti6.0\window\复习步骤31-整合框架(1)整合Spring--web

  我的网盘\我的笔记\学习文档子目录压缩\框架\工作流引擎\Activiti6.0\window\复习步骤31-整合框架(1)整合Spring--web

 */

public class TestAction implements Action {

 

    private PersonService personService;

 

    private TaskService taskService;

 

    public void setPersonService(PersonService personService) {

        this.personService = personService;

    }

 

    public void setTaskService(TaskService taskService) {

        this.taskService = taskService;

    }

 

    public String execute() throws Exception {

        List<Person> persons = personService.listPersons();

        for (Person p : persons) {

            System.out.println(p.getId());

        }

        System.out.println("===========");

        long taskCount = taskService.createTaskQuery().count();

        System.out.println(taskCount);

        return null;

    }

 

}

 

猜你喜欢

转载自blog.csdn.net/xiangshuai198807/article/details/90199763
今日推荐