zoukankan      html  css  js  c++  java
  • Activiti创建表(三)

    创建Mysql

    创建 mysql 数据库 activiti(名字任意):
    CREATE DATABASE activiti DEFAULT CHARACTER SET utf8;

    pom.xml

    <properties>
            <slf4j.version>1.6.6</slf4j.version>
            <log4j.version>1.2.12</log4j.version>
        </properties>
    
        <dependencies>
    
            <dependency>
                <groupId>org.activiti</groupId>
                <artifactId>activiti-engine</artifactId>
                <version>7.0.0.Beta1</version>
            </dependency>
    
            <dependency>
                <groupId>org.activiti</groupId>
                <artifactId>activiti-spring</artifactId>
                <version>7.0.0.Beta1</version>
            </dependency>
    
            <dependency>
                <groupId>org.activiti</groupId>
                <artifactId>activiti-bpmn-model</artifactId>
                <version>7.0.0.Beta1</version>
            </dependency>
    
            <dependency>
                <groupId>org.activiti</groupId>
                <artifactId>activiti-bpmn-converter</artifactId>
                <version>7.0.0.Beta1</version>
            </dependency>
    
            <dependency>
                <groupId>org.activiti</groupId>
                <artifactId>activiti-json-converter</artifactId>
                <version>7.0.0.Beta1</version>
            </dependency>
    
            <dependency>
                <groupId>org.activiti</groupId>
                <artifactId>activiti-bpmn-layout</artifactId>
                <version>7.0.0.Beta1</version>
            </dependency>
    
            <dependency>
                <groupId>org.activiti.cloud</groupId>
                <artifactId>activiti-cloud-services-api</artifactId>
                <version>7.0.0.Beta1</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>8.0.15</version>
            </dependency>
    
    
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
    
            <!-- log start -->
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>${log4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <!-- log end -->
    
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <version>3.4.5</version>
            </dependency>
    
            <dependency>
                <groupId>commons-dbcp</groupId>
                <artifactId>commons-dbcp</artifactId>
                <version>1.4</version>
            </dependency>
    
        </dependencies>
    
        <repositories>
            <repository>
                <id>alfresco</id>
                <name>Activiti Releases</name>
                <url>https://artifacts.alfresco.com/nexus/content/repositories/activiti-releases/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
        </repositories>

    log4j.properties

    # Set root category priority to INFO and its only appender to CONSOLE.
    #log4j.rootCategory=INFO, CONSOLE            debug   info   warn error fatal
    log4j.rootCategory=debug, CONSOLE, LOGFILE
    
    # Set the enterprise logger category to FATAL and its only appender to CONSOLE.
    log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
    
    # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
    log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
    log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
    log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m
    
    
    # LOGFILE is set to be a File appender using a PatternLayout.
    log4j.appender.LOGFILE=org.apache.log4j.FileAppender
    log4j.appender.LOGFILE.File=d:axis.log
    log4j.appender.LOGFILE.Append=true
    log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
    log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m
    

    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"
           xmlns:context="http://www.springframework.org/schema/context"
           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/contex http://www.springframework.org/schema/context/spring-context.xsd
                            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
    
        <!--数据源配置dbcp-->
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="url" value="jdbc:mysql://localhost:3306/activiti?serverTimezone=UTC" />
            <property name="username" value="root" />
            <property name="password" value="123456" />
        </bean>
        <!--activiti单独运行的ProcessEngine配置对象(processEngineConfiguration),使用单独启动方式
            默认情况下:bean的id=processEngineConfiguration
        -->
    
        <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <!--代表数据源-->
        <property name="dataSource" ref="dataSource"></property>
        <!-- <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti" />
        <property name="jdbcUsername" value="root" />
        <property name="jdbcPassword" value="root" />-->
        <!--代表是否生成表结构-->
        <property name="databaseSchemaUpdate" value="true"/>
        </bean>
    </beans>

    关于 processEngineConfiguration 中的 databaseSchemaUpdate 参数, 通过此参数设计 activiti
    数据表的处理策略,参数如下:
    false(默认):检查数据库表的版本和依赖库的版本, 如果版本不匹配就抛出异常。
    true: 构建流程引擎时,执行检查,如果需要就执行更新。 如果表不存在,就创建。
    create-drop: 构建流程引擎时创建数据库表, 关闭流程引擎时删除这些表。
    drop-create:先删除表再创建表。
    create: 构建流程引擎时创建数据库表, 关闭流程引擎时不删除这些表。

    注意:在 activiti.cfg.xml 配置文件中的 dataSource processEngineConfiguration 也可以使用一次
    性配置出来。

    <bean
    id="processEngineConfiguration"
    class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    <property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl"
    value="jdbc:mysql://localhost:3306/itcast0711activiti"/>
    <property name="jdbcUsername" value="root"/>
    <property name="jdbcPassword" value="root"/>
    <property name="databaseSchemaUpdate" value="true"/>
    </bean>

    测试类

    /**
     * 测试类
     *     作用:测试activiti所需要的25张表的生成
     */
    public class ActivitiTest {
    
    //    @Test
    //    public void testGenTable(){
    //        //条件:1.activiti配置文件名称:activiti.cfg.xml   2.bean的id="processEngineConfiguration"
    //        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    //        System.out.println(processEngine);
    //
    //       // HistoryService historyService = processEngine.getHistoryService();
    //
    //    }
    
        @Test
        public void testGenTable(){
            //1.创建ProcessEngineConfiguration对象  第一个参数:配置文件名称  第二个参数是processEngineConfiguration的bean的id
            ProcessEngineConfiguration configuration = ProcessEngineConfiguration
                    .createProcessEngineConfigurationFromResource("activiti.cfg.xml");
            //2.创建ProcesEngine对象
            ProcessEngine processEngine = configuration.buildProcessEngine();
    
            //3.输出processEngine对象
            System.out.println(processEngine);
    
    
    
        }
    }

    说明:
    1、运行以上程序段即可完成 activiti 数据库创建,通过改变 activiti.cfg.xml
    databaseSchemaUpdate 参数的值执行不同的数据表处理策略。
    2 、 上 边 的 方法 createProcessEngineConfigurationFromResource 在执行时在
    activiti.cfg.xml 中找固定的名称 processEngineConfiguration
    也可以使用重载方法调用,这时可以不用限定 processEngineConfiguration 名称

     Activiti 的表都以 ACT_开头。 第二部分是表示表的用途的两个字母标识。 用途也和服务的 API 对

    ACT_RE_*: 'RE'表示 repository。 这个前缀的表包含了流程定义和流程静态资源 (图片,
    规则,等等)。
    ACT_RU_*: 'RU'表示 runtime。 这些运行时的表,包含流程实例,任务,变量,异步任务,
    等运行中的数据。 Activiti 只在流程实例执行过程中保存这些数据, 在流程结束时就会删
    除这些记录。 这样运行时表可以一直很小速度很快。
    ACT_HI_*: 'HI'表示 history。 这些表包含历史数据,比如历史流程实例, 变量,任务等
    等。
    ACT_GE_*: GE 表示 general。 通用数据, 用于不同场景下。

  • 相关阅读:
    静态变量一定要先声明后赋值
    建议3 三元操作的类型必一致
    IDEA 创建 Maven web项目注意事项
    js不同类型作比较
    exception中return方法
    exception 打印出异常栈踪迹
    spring controller使用了@ResponseBody却返回xml
    springboot中的406(Not Acceptable)错误
    把本地建好的项目提交到git上
    java基础---------方法和方法重载
  • 原文地址:https://www.cnblogs.com/dalianpai/p/11843756.html
Copyright © 2011-2022 走看看