码迷,mamicode.com
首页 > 数据库 > 详细

activiti的基础环境搭建创建数据库表及策略

时间:2018-05-03 23:58:13      阅读:389      评论:0      收藏:0      [点我收藏+]

标签:ram   get   inpu   junit   lease   tcl   class   creat   uil   

博主使用为activiti5.22的版本。

1、创建maven工程。

2、在pom文件中引入所需要的包,如:activiti包、数据库包。

这是我引用的包:

<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.22.0</version>
</dependency>

<!-- <dependency> 
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId> 
<version>1.4</version>
</dependency> -->

<dependency> 
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId> 
<version>1.1.2</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.22.0</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5-pre10</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.8.RELEASE</version>
</dependency>
<dependency>
<groupId>com.googlecode.ehcache-spring-annotations</groupId>
<artifactId>ehcache-spring-annotations</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>

 

 

引入pom文件完毕之后,在maven的resources下新建activiti.cfg.xml文件,配置数据源及引擎类。后期与spring框架结合使用,记得把此xml文件引入到spring中。                                     

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/activiti"></property>
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>

<bean id="processEngineConfiguration" 
class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> 
<property name="dataSource" ref="dataSource"></property>
</bean>

 

 

下面是流程引擎配置类的几种创建方式,            

  @Test
    public void createDataTable(){
        ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
        processEngineConfiguration.setJdbcDriver("com.mysql.jdbc.Driver");
        processEngineConfiguration.setJdbcUrl("jdbc:mysql://localhost:3306/activiti");
        processEngineConfiguration.setJdbcUsername("root");
        processEngineConfiguration.setJdbcPassword("root");
        /**
         * true:如果不存在表就创建,存在就直接使用。(默认使用该策略,真实项目不推荐使用,如果目前使用较低版本,贸然引入了更高的版本后,
         * 上线之后,就会导致activiti数据库环境升级版本,可能造成线上部分表无法使用。顺便一提:activiti的版本只能向上升级,无法降级处理)
         * false:流程引擎启动的时候,不会创建表,如果不存在就报错,存在就直接使用。(建议使用)
         * create-drop:每次都是创建表,然后删除表,需要手动调用引擎类的close方法(更不建议使用)
         */
//        processEngineConfiguration.setDatabaseSchemaUpdate("true");
//        processEngineConfiguration.setDatabaseSchemaUpdate("false");
        processEngineConfiguration.setDatabaseSchemaUpdate("create-drop");
        ProcessEngine buildProcessEngine = processEngineConfiguration.buildProcessEngine();
//        buildProcessEngine.close();
        System.out.println(buildProcessEngine);
    }
/**
     * 配置文件的方式创建 (流方式一)
     */
    @Test
    public void createTabale1(){
        InputStream inputStream=App.class.getClassLoader().getResourceAsStream("activiti.cfg.xml");
        ProcessEngineConfiguration processEngineConfigurationFromInputStream = ProcessEngineConfiguration.
                createProcessEngineConfigurationFromInputStream(inputStream);
        ProcessEngine processEngine = processEngineConfigurationFromInputStream.buildProcessEngine();
        System.out.println(processEngine);
    }
    
    /**
     * 配置文件的方式创建 (流方式二)
     * 第一种方式是调用第二种方式的源码
     */
    @Test
    public void createTabale2(){
        InputStream inputStream=App.class.getClassLoader().getResourceAsStream("activiti.cfg.xml");
        ProcessEngineConfiguration processEngineConfigurationFromInputStream = ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(inputStream, "processEngineConfiguration");
        ProcessEngine processEngine = processEngineConfigurationFromInputStream.buildProcessEngine();
        System.out.println(processEngine);
    }
    /**
     * 配置文件的方式创建 (资源方式一)
     * 第一种方式是调用第二种方式的源码
     */
    @Test
    public void createTabale3(){
        String resource="activiti.cfg.xml";
        ProcessEngineConfiguration processEngineConfigurationFromResource = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(resource);
        ProcessEngine buildProcessEngine = processEngineConfigurationFromResource.buildProcessEngine();
        System.out.println(buildProcessEngine);
    }
    
    /**
     * 配置文件的方式创建 (资源方式二)
     * 第一种方式是调用第二种方式的源码
     */
    @Test
    public void createTabale4(){
        String resource="activiti.cfg.xml";
        ProcessEngineConfiguration processEngineConfigurationFromResource = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(resource,"processEngineConfiguration");
        ProcessEngine buildProcessEngine = processEngineConfigurationFromResource.buildProcessEngine();
        System.out.println(buildProcessEngine);
    }
    
    /**
     * 默认的方式创建 (资源方式一)
     * 通过文件的位置:activiti.cfg.xml。此处我的文件位置是在resources下
     */
    @Test
    public void createTabale5(){
        ProcessEngineConfiguration processEngineConfigurationFromResource = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
        ProcessEngine buildProcessEngine = processEngineConfigurationFromResource.buildProcessEngine();
        System.out.println(buildProcessEngine);
    }

运行后大家会发现数据库多了二十几张表,都是activiti自己的表结构,没错吧。后期与实际业务结合的时候,可根据需求再自定义表与之结合即可。

后续会补上aciviti的表结构详解,尽请期待!

                                                                                  

activiti的基础环境搭建创建数据库表及策略

标签:ram   get   inpu   junit   lease   tcl   class   creat   uil   

原文地址:https://www.cnblogs.com/shijianhenjinpo/p/8988267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!