http://www.itxxz.com/a/gaoji/2015/0122/activiti_spring_mybatis.html
上一篇中我们介绍了eclipse整合activiti插件的过程,今天螃蟹就讲解下activiti5.17.0与spring和mybatis的整合。
首先我们看一下activiti所需要的包,
我们解压从官网下载的activiti-5.17.0后,在wars文件夹下有两个example实例,这两个实例用所用的基本就是activiti所需的所有jar包了。
spring和mybatis的jar包,可以用war实例中提供的,也可以自己选择合适的版本下载,这是实例的源码,会在该系列教程结束后发放出来。
下面我们开始看配置文件:
首先是web.xml
这里主要是指定项目启动时,需要加载的配置文件及初始化类
spring与activit配置文件整合
配置主要集中在applicationContext.xml文件中。
主要有以下几点:
1、配置数据库数据源,这里以mysql为例
2、启用spring 的注解模式
3、配置事务
4、配置activiti的引擎,也即是activiti的主类。
5、配置activiti的各种服务类。
6、配置工具类,主要是避免调用过程中,重复调用和过多的new对象,这里我们通过spring来处理。
配置文件如下:
首先我们看一下activiti所需要的包,
我们解压从官网下载的activiti-5.17.0后,在wars文件夹下有两个example实例,这两个实例用所用的基本就是activiti所需的所有jar包了。
spring和mybatis的jar包,可以用war实例中提供的,也可以自己选择合适的版本下载,这是实例的源码,会在该系列教程结束后发放出来。
下面我们开始看配置文件:
首先是web.xml
这里主要是指定项目启动时,需要加载的配置文件及初始化类
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- id="WebApp_ID" version="2.5">
- <display-name>itxxz</display-name>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <!-- 加载spring主配置文件 -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- classpath*:/applicationContext.xml
- </param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
- </listener>
- <!-- 配置spring拦截器 -->
- <servlet>
- <servlet-name>springMvc</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <!-- 配置请求路径 -->
- <param-value>classpath:spring-servlet-config.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup><!-- load-on-startup必须放在最后 -->
- </servlet>
- <servlet-mapping>
- <servlet-name>springMvc</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <!-- 验证码 -->
- <servlet>
- <servlet-name>authCode</servlet-name>
- <servlet-class>com.itxxz.servlet.AuthCodeServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>authCode</servlet-name>
- <url-pattern>/authCode</url-pattern>
- </servlet-mapping>
- <!-- 一缕转换为UTF-8编码 -->
- <filter>
- <filter-name>itxxzEncoding</filter-name>
- <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- <init-param>
- <param-name>forceEncoding</param-name>
- <param-value>true</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>itxxzEncoding</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <!-- sesson超时时间 -->
- <session-config>
- <session-timeout>180</session-timeout>
- </session-config>
- <!-- 4040页面返回 -->
- <error-page>
- <error-code>404</error-code>
- <location>/WEB-INF/error.jsp</location>
- </error-page>
- <welcome-file-list>
- <welcome-file>/WEB-INF/pages/login.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
spring与activit配置文件整合
配置主要集中在applicationContext.xml文件中。
主要有以下几点:
1、配置数据库数据源,这里以mysql为例
2、启用spring 的注解模式
3、配置事务
4、配置activiti的引擎,也即是activiti的主类。
5、配置activiti的各种服务类。
6、配置工具类,主要是避免调用过程中,重复调用和过多的new对象,这里我们通过spring来处理。
配置文件如下:
- <?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:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.1.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
- <property name="driverClass">
- <value>com.mysql.jdbc.Driver</value>
- </property>
- <property name="jdbcUrl">
- <value>jdbc:mysql://127.0.0.1:3306/itxxz?useUnicode=true&characterEncoding=utf-8</value>
- </property>
- <property name="user">
- <value>root</value>
- </property>
- <property name="password">
- <value>root</value>
- </property>
- <property name="minPoolSize">
- <value>10</value>
- </property>
- <property name="maxPoolSize">
- <value>500</value>
- </property>
- <property name="initialPoolSize">
- <value>10</value>
- </property>
- <property name="maxIdleTime">
- <value>25000</value>
- </property>
- <property name="acquireIncrement">
- <value>5</value>
- </property>
- <property name="acquireRetryAttempts">
- <value>30</value>
- </property>
- <property name="acquireRetryDelay">
- <value>1000</value>
- </property>
- <property name="testConnectionOnCheckin">
- <value>false</value>
- </property>
- <property name="automaticTestTable">
- <value>t_c3p0</value>
- </property>
- <property name="idleConnectionTestPeriod">
- <value>18000</value>
- </property>
- <property name="checkoutTimeout">
- <value>5000</value>
- </property>
- </bean>
- <!-- 配置sqlSessionFactory -->
- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="dataSource"></property>
- <property name="configLocation" value="classpath:mybatis-config.xml"></property>
- </bean>
- <!-- 配置事务 -->
- <bean id="txManager"
- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"></property>
- </bean>
- <!--使用基于注解方式配置事务 -->
- <tx:annotation-driven transaction-manager="txManager" />
- <!-- 开启自动扫描 -->
- <context:annotation-config/>
- <context:component-scan base-package="com.itxxz" use-default-filters="false">
- <context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
- <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />
- <context:include-filter type="annotation" expression="org.springframework.stereotype.Component" />
- </context:component-scan>
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="basePackage" value="com.itxxz" />
- </bean>
- <!-- activiti事物管理 -->
- <bean id="transactionManager"
- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
- </bean>
- <!-- 加载activiti引擎 -->
- <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
- <property name="processEngineConfiguration" ref="processEngineConfiguration" />
- </bean>
- <bean id="processEngineConfiguration"
- class="org.activiti.spring.SpringProcessEngineConfiguration">
- <property name="dataSource" ref="dataSource" />
- <property name="transactionManager" ref="transactionManager" />
- <property name="databaseSchemaUpdate" value="true" />
- <property name="jobExecutorActivate" value="false" />
- </bean>
- <!-- activiti的各种服务接口 -->
- <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="commonUtil" class="com.itxxz.workflow.util.CommonUtil">
- </bean>
- </beans>
spring-servlet-config.xml
到这里基本上就完成大部分工作了,还有一个文件,就是spring-servlet-config.xml。
通常我们会在这里配置静态资源或者试图页面等,以下配置只是简单配置了三点内容:
1、配置注解的扫描路径,也就是指定哪些地方需要使用注解
2、配置了静态资源的加载路径,也就是说这些路径不需要通过spring的拦截,可以直接调用。
3、配置jsp页面的试图,我们可以为其指定命名空间,也就是jsp页面的前缀。举个列子,如果我们调用的是WEB-INF/pages/itxxz.jsp这个页面,在配置好前缀路径WEB-INF/pages后,我们直接返回itxxz.jsp,spring会自动给填充缺省的路径。
配置代码如下: itxxz.com
- <context:component-scan base-package="com.itxxz.*.web,com.itxxz.sys.*.web,com.jfok.server" use-default-filters="false">
- <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
- </context:component-scan>
- <!-- 配置静态资源 -->
- <mvc:resources mapping="/images/**" location="/images/" />
- <mvc:resources mapping="/css/**" location="/css/" />
- <mvc:resources mapping="/fonts/**" location="/fonts/" />
- <mvc:resources mapping="/upload/**" location="/upload/" />
- <!-- 使用jsp作为视图 -->
- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="viewClass">
- <value>org.springframework.web.servlet.view.JstlView</value>
- </property>
- <property name="prefix" value="/WEB-INF/pages/"></property>
- <property name="suffix" value=".jsp"></property>
- </bean>
配置完成后,我们就可以通过tomcat启动来测试一下,如下图便是成功启动了。
相关推荐
本项目是关于"activiti+spring+spring Mvc+mybatis+maven"的整合,旨在创建一个基于Activiti工作流引擎、Spring、Spring MVC、MyBatis以及Maven的开发环境。下面将详细介绍这些技术及其整合过程。 首先,`activiti`...
本后台管理系统,采用流行的框架springMvc+spring+mybatis+shiro+redis+ehcache开发,实现了权限管理(菜单权限、数据权限),solr全文搜索引擎,activiti工作流程引擎,cas单点登陆等功能,完善的代码生成器 后期还...
在本项目"activiti+springMVC+mybatis rest风格整合demo"中,开发者通过集成Activiti、Spring MVC和MyBatis三个核心组件,构建了一个基于RESTful API的工作流管理系统。这个项目对于初学者来说是一个很好的学习资源...
此项目为springmvc、Mybatis、EHcache、maven、Spring security3、activiti5工作流的整合 是一个基于数据库的权限管理demo项目、使用mysql数据库 项目运行前需要构建maven私服 而且有些jar包私服中肯定没有,需要...
基于 springboot+mybatis_+shiro + redis+activiti+quarts+quartz+vue 写的一个前后分离办公企业管理系统 ,通用服务端,用于学习。 使用技术 服务端: springboot(2.2.1) + mybatis-push + shiro(1.4.0) + redis +...
【标题】"activiti工作流demo,数据库使用mysql,spring + mybatis + activiti,里面参.zip" 提供了一个实际的应用场景,展示了如何在Java环境中集成流行的工作流引擎Activiti,以及如何与MySQL数据库、Spring框架和...
标题中的“activiti+spring mvc+maven+extjs mvc+mybatis”是一个集成的IT解决方案,用于构建一个简单的请假工作流程应用。这个项目利用了多种技术来创建一个前端和后端无缝协作的系统。 1. **Activiti**:Activiti...
这些jar包包括了Spring的核心模块(如spring-context、spring-beans)、MyBatis的主库和驱动适配器(如mybatis、mysql-connector-java),以及Activiti的运行时库(如activiti-engine、activiti-bpmn-converter)。...
个人编写的spring+springMVC+Mybatis+Activiti+mysql实现请假流程,流程使用activity进行管理,适合刚接触过Activiti的新手学习使用; 由于空间较少,一些jar文件被删了,如果有需要的话,请联系我提供 如果大家觉得...
【标题】"spring4+springMVC+mybatis+activiti+maven" 是一个常见的企业级Java应用架构组合,用于构建高效、灵活的Web应用程序。这个组合包含了四个核心组件:Spring 4作为整体框架,Spring MVC作为MVC(模型-视图-...
【标题】"Spring MVC + Activiti + MyBatis 小整合"揭示了这个项目的核心技术栈,它是一个基于Java的企业级应用示例,用于展示如何将这三个流行的技术框架集成在一起,构建一个完整的业务流程管理系统。Spring MVC是...
Java控制台+activiti+springboot+mybatis实现账务报销工作流程.md
基于Spring+SpringMVC+Mybatis+Shiro的商城分布式系统架构源码.zip my-shop基于Spring+SpringMVC+Mybatis+ Shiro分布式敏捷开发系统架构,提供整套公共微服务服务模块:内容管理、支付中心、用户管理(包括第三方)...
基于 springboot+myvatis_+ mvc + activiti+quarts+quartz 写的一个办公企业管理系统 OA 软件架构 springboot+myvatis_+ mvc + activiti+quarts+quartz 说明 功能: 用户模块 日志模块 考勤模块 工作流模块 请假 ...
技术栈:springboot+activity+mybatis+activity工作流审批分为:员工用户、部门经理、boss三种角色
本教程将探讨如何将Spring MVC、MyBatis和Activiti这三大框架整合在一起,以实现一个功能丰富的业务流程管理系统。 首先,Spring MVC是Spring框架的一个模块,主要用于构建Web应用程序的Model-View-Controller(MVC...
【Activity整合SpringMvc+Mybatis】是一个常见的企业级应用架构模式,它将业务流程管理(BPM)系统Activiti与Web应用框架Spring MVC和持久层框架Mybatis相结合,以实现高效、灵活的业务流程自动化。这个代码Demo展示...
标题中的"Hibernate+springMVC+Mybatis+Activiti5.16+Android客户端+mysql数据库"是一个典型的Java企业级应用架构,它涉及到多个技术栈的整合,包括持久层、控制层、服务流程管理和移动客户端开发。让我们逐一深入...
标题中的“springboot+activiti+vue+thymleaf 版本”指的是一个基于Spring Boot、Activiti、Vue.js和Thymeleaf的综合工作流管理系统。这个系统结合了四个关键的技术栈,构建了一个功能丰富的业务流程自动化平台。 1...
NULL 博文链接:https://whatisjavabean.iteye.com/blog/2017035