Activiti工作流环境配置(二)

本篇主要是实现Spring与Activiti的集成。
Spring集成环境搭建
1) web.xml配置


<web-app version="3.1" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd">

	<display-name>spring-activiti-demodisplay-name>

	
	<filter>
		<description>字符集编码过滤器description>
		<filter-name>encodingFilterfilter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
		<init-param>
			<description>字符集编码description>
			<param-name>encodingparam-name>
			<param-value>UTF-8param-value>
		init-param>
	filter>
	<filter-mapping>
		<filter-name>encodingFilterfilter-name>
		<url-pattern>/*url-pattern>
	filter-mapping>
  	

	
	<context-param>
		<description>配置spring监听description>
		<param-name>contextConfigLocationparam-name>
		<param-value>
               classpath:springContext.xmlparam-value>
	context-param>
    
	<listener>
		<description>spring监听器description>
		<listener-class>
            org.springframework.web.context.ContextLoaderListener
        listener-class>
	listener>
	<listener>
		<description>防止spring内存溢出的监听器description>
		<listener-class>
            org.springframework.web.util.IntrospectorCleanupListener
        listener-class>
	listener>
	
	
	
	<servlet>
		<description>SpringMVC分发器  DispatcherServletdescription>
		<servlet-name>SpringMVCservlet-name>
		<servlet-class>
             org.springframework.web.servlet.DispatcherServlet
        servlet-class>
		<init-param>
			<description>SpringMVC配置文件description>
			<param-name>contextConfigLocationparam-name>
			<param-value>
				classpath:springContext-SpringMVC.xml
			param-value>
		init-param>
		<load-on-startup>1load-on-startup>
	servlet>

	<servlet-mapping>
		<servlet-name>SpringMVCservlet-name>
		<url-pattern>*.dourl-pattern>
	servlet-mapping>
	

	<welcome-file-list>
		<welcome-file>index.jspwelcome-file>
	welcome-file-list>
	 
web-app>

2) 核心加载配置文件springContext.xml


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

    
    <context:component-scan base-package="com.giser.*">
        
    context:component-scan>
    
    <mvc:annotation-driven/>

	<import resource="classpath:springContext-tx.xml"/>
	<import resource="classpath:springContext-MyBatis.xml"/>
	<import resource="classpath:springContext-Activiti.xml"/>

beans>

3) 事务管理集成文件springContext-tx.xml


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

    
    <context:property-placeholder location="classpath*:jdbc.properties"/>

    
    <bean id="jdbcDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    bean>

    <bean id="jdbcTemplate" name="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="jdbcDataSource"/>
    bean>

    
    
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="jdbcDataSource">property>
    bean>

    
    <tx:annotation-driven transaction-manager="transactionManager"/>

beans>

4) MyBatis集成springContext-MyBatis.xml


<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">


	
	<context:property-placeholder
		location="classpath:jdbc.properties" ignore-unresolvable="true" />

	
	
	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	bean>

	<bean id="sqlSessionFactory"
		class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		
		<property name="mapperLocations">
			<list>
				<value>classpath:com/giser/activiti/mapper/*.xmlvalue>
			list>
		property>
	bean>

	
	<bean id="mapperScannerConfigurer"
		class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.giser.activiti.dao" /> 
		<property name="sqlSessionFactoryBeanName"
			value="sqlSessionFactory">property>
	bean>
	
	    
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource">property>
    bean>

beans>

5) SpringMVC的集成springContext-SpringMVC.xml


<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

	
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
		<property name="prefix" value="/WEB-INF/views" />
		<property name="suffix" value=".jsp" />
	bean>
	


	
	<mvc:default-servlet-handler />

	
	<mvc:resources location="/resources/" mapping="/resources/**"/>
	<mvc:resources location="diagram-viewer/" mapping="diagram-viewer/**" />
	<mvc:resources location="editor-app/" mapping="editor-app/**" />
	<mvc:resources location="/" mapping="/**.html" />
	<mvc:resources location="/" mapping="/**.jsp" />
	
	


 	
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding">
			<value>UTF-8value>
		property>
		<property name="maxUploadSize">
			
			<value>32505856value>
		property>
		<property name="maxInMemorySize">
			<value>4096value>
		property>
	bean>
	
	
	<bean id="mappingJacksonHttpMessageConverter"
		class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
		<property name="supportedMediaTypes">
			<list>
				<value>text/html;charset=UTF-8value>
			list>
		property>
	bean>
 
	
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<ref bean="mappingJacksonHttpMessageConverter" />
			list>
		property>
	bean>

 beans>
 

6) 集成Activiti工作流框架springContext-Activiti.xml


<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

 	
	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="defaultAutoCommit" value="false" />
	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"/>
		
        <property name="asyncExecutorEnabled" value="false" />
        <property name="asyncExecutorActivate" value="false" />

        
        
        
        <property name="processDefinitionCacheLimit" value="10"/>

        
        

        
        

        
        <property name="activityFontName" value="宋体"/>
        <property name="labelFontName" value="宋体"/>

        

        
        

        
        
        
        
    bean>
	
	

 
    
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean" destroy-method="destroy">
        <property name="processEngineConfiguration" ref="processEngineConfiguration"/>
    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="formService" factory-bean="processEngine" factory-method="getFormService"/>
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/>
    <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
    
      

beans>

7) 依赖管理pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0modelVersion>
	<groupId>com.gisergroupId>
	<artifactId>spring-activiti-demoartifactId>
	<packaging>warpackaging>
	<version>0.0.1-SNAPSHOTversion>
	<name>spring-activiti-demo Maven Webappname>
	<url>http://maven.apache.orgurl>
	<properties>
		<spring.version>4.3.9.RELEASEspring.version>
		<activiti.version>5.22.0activiti.version>
		<mysql.version>5.1.34mysql.version>
		<maven.compiler.target>1.8maven.compiler.target>
		<maven.compiler.source>1.8maven.compiler.source>
	properties>

	<dependencies>
		
		<dependency>
			<groupId>junitgroupId>
			<artifactId>junitartifactId>
			<version>4.12version>
			<scope>testscope>
		dependency>

		
		
		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-engineartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-springartifactId>
			<version>${activiti.version}version>
			<exclusions>
				<exclusion>
					<artifactId>commons-dbcpartifactId>
					<groupId>commons-dbcpgroupId>
				exclusion>
			exclusions>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-bpmn-modelartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-bpmn-converterartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-bpmn-layoutartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-json-converterartifactId>
			<version>${activiti.version}version>
		dependency>


		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-common-restartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-crystalballartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-diagram-restartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-explorerartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-image-generatorartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-modelerartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-simple-workflowartifactId>
			<version>${activiti.version}version>
		dependency>

		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-process-validationartifactId>
			<version>${activiti.version}version>
		dependency>

		
		
		<dependency>
			<groupId>joda-timegroupId>
			<artifactId>joda-timeartifactId>
			<version>2.10.6version>
		dependency>


		<dependency>
			<groupId>javax.activationgroupId>
			<artifactId>activationartifactId>
			<version>1.1version>
		dependency>

		<dependency>
			<groupId>commons-dbcpgroupId>
			<artifactId>commons-dbcpartifactId>
			<version>1.4version>
		dependency>
		<dependency>
			<groupId>org.mybatisgroupId>
			<artifactId>mybatisartifactId>
			<version>3.2.5version>
		dependency>

		
		<dependency>
			<groupId>org.mybatisgroupId>
			<artifactId>mybatis-springartifactId>
			<version>1.3.2version>
		dependency>


		<dependency>
			<groupId>org.apache.commonsgroupId>
			<artifactId>commons-lang3artifactId>
			<version>3.1version>
		dependency>
		
		
		<dependency>
		    <groupId>commons-langgroupId>
		    <artifactId>commons-langartifactId>
		    <version>2.6version>
		dependency>
		
		
		<dependency>
		    <groupId>org.apache.commonsgroupId>
		    <artifactId>commons-emailartifactId>
		    <version>1.5version>
		dependency>
		
		
		<dependency>
			<groupId>commons-fileuploadgroupId>
			<artifactId>commons-fileuploadartifactId>
			<version>1.4version>
		dependency>
		<dependency>
			<groupId>commons-iogroupId>
			<artifactId>commons-ioartifactId>
			<version>2.6version>
		dependency>

		
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-coreartifactId>
			<version>${spring.version}version>
		dependency>

		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-beansartifactId>
			<version>${spring.version}version>
		dependency>

		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-contextartifactId>
			<version>${spring.version}version>
		dependency>

		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-txartifactId>
			<version>${spring.version}version>
		dependency>

		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-webartifactId>
			<version>${spring.version}version>
		dependency>
		
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-jdbcartifactId>
			<version>${spring.version}version>
		dependency>
		
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-expressionartifactId>
			<version>${spring.version}version>
		dependency>

		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-testartifactId>
			<version>${spring.version}version>
			<scope>testscope>
		dependency>

		
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-webmvcartifactId>
			<version>${spring.version}version>
		dependency>

		
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-ormartifactId>
			<version>${spring.version}version>
		dependency>

		
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-aopartifactId>
			<version>${spring.version}version>
		dependency>
		
		<dependency>
			<groupId>org.aspectjgroupId>
			<artifactId>aspectjweaverartifactId>
			<version>1.8.4version>
		dependency>
		
		
		<dependency>
		    <groupId>aopalliancegroupId>
		    <artifactId>aopallianceartifactId>
		    <version>1.0version>
		dependency>
		
		
		
		
		<dependency>
			<groupId>mysqlgroupId>
			<artifactId>mysql-connector-javaartifactId>
			<version>${mysql.version}version>
		dependency>

		
		<dependency>
			<groupId>com.mchangegroupId>
			<artifactId>c3p0artifactId>
			<version>0.9.5-pre10version>
		dependency>
		
		
		<dependency>
		    <groupId>com.h2databasegroupId>
		    <artifactId>h2artifactId>
		    <version>1.4.199version>
		dependency>
		
		

		<dependency>
			<groupId>com.fasterxml.jackson.coregroupId>
			<artifactId>jackson-coreartifactId>
			<version>2.8.9version>
		dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.coregroupId>
			<artifactId>jackson-databindartifactId>
			<version>2.8.9version>
		dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.coregroupId>
			<artifactId>jackson-annotationsartifactId>
			<version>2.8.9version>
		dependency>

		
		<dependency>
			<groupId>javax.servletgroupId>
			<artifactId>javax.servlet-apiartifactId>
			<version>3.1.0version>
			<scope>providedscope>
		dependency>
		<dependency>
			<groupId>javax.servletgroupId>
			<artifactId>jstlartifactId>
			<version>1.2version>
		dependency>

		<dependency>
			<groupId>org.jsongroupId>
			<artifactId>org.jsonartifactId>
			<version>chargebee-1.0version>
		dependency>

		
		<dependency>
			<groupId>net.sf.json-libgroupId>
			<artifactId>json-lib-ext-springartifactId>
			<version>1.0.2version>
		dependency>

		
		<dependency>
			<groupId>org.slf4jgroupId>
			<artifactId>slf4j-apiartifactId>
			<version>1.6.1version>
		dependency>
		<dependency>
			<groupId>org.slf4jgroupId>
			<artifactId>slf4j-log4j12artifactId>
			<version>1.6.1version>
		dependency>
		<dependency>
			<groupId>log4jgroupId>
			<artifactId>log4jartifactId>
			<version>1.2.16version>
		dependency>

		
		<dependency>
			<groupId>com.alibabagroupId>
			<artifactId>fastjsonartifactId>
			<version>1.2.46version>
		dependency>
		

		
		<dependency>
			<groupId>javax.servletgroupId>
			<artifactId>jsp-apiartifactId>
			<version>2.0version>
		dependency>

	dependencies>


	<build>
		<finalName>spring-activiti-demofinalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-compiler-pluginartifactId>
				<version>3.6.0version>
				<configuration>
					<source>1.8source>
					<target>1.8target>
				configuration>
			plugin>

			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-source-pluginartifactId>
				<version>3.2.1version>
				<executions>
					<execution>
						<id>attach-sourcesid>
						<phase>verifyphase>
						<goals>
							<goal>jar-no-forkgoal>
						goals>
					execution>
				executions>
			plugin>

		plugins>
	build>
project>


8) jdbc.properties

#mysql jdbc
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/activiti?useSSL=false&zeroDateTimeBehavior=round&useUnicode=yes&characterEncoding=UTF8
jdbc.username=root
jdbc.password=root

至此,集成框架搭建完成,启动运行后,会在数据库中创建25张表。
Activiti工作流环境配置(二)_第1张图片

你可能感兴趣的:(Activiti)