Activiti整合Spring---来自程序lee的自我概述

Activiti整合Spring

一. 搭建框架

  1. 工程需要的一个包结构:

controller

service

domain

mapper

utils

webapp\WEB-INF

  1. 导入坐标

二. 编写配置文件

需要大概7个配置文件:

​ xml的名字最好统一一些(如applicationContext-*),最后在web.xml中通过contextConfigLocation可以统一监听

mybatis-config.xml
一般也就写到spring.xml 中了,因为配置少;如果配置多可以单独写出来,然后在spring中引用一下

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<!-- 起别名 -->
	<typeAliases>
		<!-- <typeAlias alias="User" type="cn.neudu.mybatis.pojo.User"/> -->
		<!-- 批量起别名 : 自动扫描整个包,包中的类的别名就是类名 
		<package name="cn.neuedu.ssm.pojo"/>-->
	</typeAliases>
	<!-- 分页插件: 拦截器 -->
    <plugins>
    	<plugin interceptor="com.github.pagehelper.PageHelper">
    		<!-- 指定数据库的方言(类型)必须  -->
    		<property name="dialect" value="mysql"/>
    		<property name="reasonable" value="true"/>
    	</plugin>
    </plugins>
</configuration>

activiti.cfg.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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
	<!-- 创建一个流程引擎的配置对象 -->
  <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <!-- 关联公共的数据源,不需要在手动编写数据源 -->
    <property name="dataSource" ref="dataSource"></property>
    <property name="transactionManager" ref="transactionManager"></property>
     <!-- 设置数据库schema的更新方式 -->
    <property name="databaseSchemaUpdate" value="true"/>
     <!-- 是否启动jobExecutor -->
    <property name="jobExecutorActivate" value="false"/>
  </bean>
  <!-- 创建一个流程引擎bean 得到对象就是ProcessEngine processEngine IOC-->
  <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    <!-- 加载配置 -->
    <property name="processEngineConfiguration" ref="processEngineConfiguration"/>
  </bean>
  <!--定义工作流的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="managementService" factory-bean="processEngine" factory-method="getManagementService"/>
   <!-- 工作流唯一服务 -->
  <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>
  <bean id="formService" factory-bean="processEngine" factory-method="getFormService"></bean>
<!-- 上面的内容就是工作流引擎的持久层+服务层的配置 -->
</beans>

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: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.xsd
			    http://www.springframework.org/schema/context
			    http://www.springframework.org/schema/context/spring-context.xsd
			    http://www.springframework.org/schema/aop
			    http://www.springframework.org/schema/aop/spring-aop.xsd
			    http://www.springframework.org/schema/tx
			    http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--包扫描-->
    <context:component-scan base-package="com.lee.activiti">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!--引入外部配置文件-->
    <context:property-placeholder location="classpath:db.properties"/>
    <!--数据源-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <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="maxWait" value="9000"></property>
    </bean>
    <!--事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--这个bean他就可以产生一个sqlSession的工厂-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--数据源-->
        <property name="dataSource" ref="dataSource"/>
        <!--配置别名包-->
        <property name="typeAliasesPackage" value="com.lee.activiti.domain"/>
        <!--如果还需要其他的mybatis的配置,那么可以使用这个引入一个单独mybatis的配置文件-->
        <!--<property name="configLocation" value="classpath:mybatis-config.xml"></property>-->
    </bean>
    <!--mapper扫描器-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.lee.activiti.mapper"/>
    </bean>
</beans>

springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        https://www.springframework.org/schema/mvc/spring-mvc.xsd
		http://www.springframework.org/schema/aop
        https://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd">

    <!--包扫描-->
    <context:component-scan base-package="com.lee.activiti.controller"/>
    <!--注解驱动-->
    <mvc:annotation-driven/>
    <!--视图解析器-->
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/view"/>
        <property name="suffix" value=".jsp"/>
    </bean>
    <!--释放静态资源-->
    <mvc:default-servlet-handler />
    <!--还可能有:拦截器  文件上传解析器  类型转换器-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="10240000"></property>
        <property name="defaultEncoding" value="utf-8"></property>
    </bean>

</beans>

db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///db_activiti?characterEncoding=utf-8&useSSL=false
jdbc.username=root
jdbc.password=root

log4j.properties

#设置Logger输出级别和输出目的地
log4j.rootLogger=DEBUG, Console ,logfile
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n 
log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG 

### 把日志信息输出到文件###
log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=qf.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %l %F %p %m%n

web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app version="3.0"
         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_0.xsd">

    <!--加入spring的监听器-->
    <!--这个listener默认会读取/WEB-INF/applicationContext.xml最为配置文件
    但是也允许你重新指定配置文件的位置
    -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext-*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!--前端控制器-->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext-springmvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <!--中文乱码过滤器-->
    <filter>
        <filter-name>characterEncodingFilter</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>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

三. 工具类

比如什么日期转换,什么邮件监听,还有监听器等等,这里就不列举了… 大家就看破不说破 -.-

当然,剩下的比如controller,service,mapper等等模块儿,与ssm写法完全一样,我也就不多说了,咳咳…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值