第一步是先集成好activiti,我使用的是5.22.0,使用springboot集成,pom文件如下:


<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<span class="hljs-tag">&lt;<span class="hljs-name">properties</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">java.version</span>&gt;</span>1.8<span class="hljs-tag">&lt;/<span class="hljs-name">java.version</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">activiti.version</span>&gt;</span>5.22.0<span class="hljs-tag">&lt;/<span class="hljs-name">activiti.version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">properties</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-thymeleaf<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.activiti<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>activiti-spring-boot-starter-basic<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>${activiti.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>mysql<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mysql-connector-java<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>runtime<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-test<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>

配置springboot的启动配置文件中的数据库,我们指定一个独立的数据库来进行创建activiti的数据库

spring:
datasource:
url: jdbc:mysql://localhost:3306/activiti?characterEncoding=utf8
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: false debug: true

运行启动类,

@SpringBootApplication
public class ActivitiApplication {
<span class="hljs-comment">/**
* Description:
* <span class="hljs-doctag">@author</span> Liu Wenjie
* <span class="hljs-doctag">@date</span> 2018年2月11日 上午10:38:00
* <span class="hljs-doctag">@param</span> args
*/</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
SpringApplication.run(ActivitiApplication.class, args);
}

}

我们打开数据库,可以看到已经动态生成了对应的数据库文件,而正常业务我们不想使用activiti的数据库作为数据源的链接源,那么我们就修改配置文件的链接到test 数据库上,修改后的配置如下:

spring:
datasource:
url: jdbc:mysql://localhost:3306/test?characterEncoding=utf8
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: false debug: true

如果我们现在启动,那么activiti会默认在test database上创建数据库表结构,这时候我们需要增加一个配置类,

@Component
public class ActivitiProcessEngineConfigurationConfigurer implements ProcessEngineConfigurationConfigurer {
<span class="hljs-comment">/**
* &lt;p&gt;Description: &lt;/p&gt;
* <span class="hljs-doctag">@author</span> Liu Wenjie
* <span class="hljs-doctag">@date</span> 2018年2月12日 上午11:09:19
* <span class="hljs-doctag">@param</span> processEngineConfiguration
* <span class="hljs-doctag">@see</span> org.activiti.spring.boot.ProcessEngineConfigurationConfigurer#configure(org.activiti.spring.SpringProcessEngineConfiguration)
*/</span>
<span class="hljs-meta">@Override</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">configure</span><span class="hljs-params">(SpringProcessEngineConfiguration processEngineConfiguration)</span> </span>{
processEngineConfiguration.setDatabaseTablePrefix(<span class="hljs-string">"activiti."</span>);
processEngineConfiguration.setTablePrefixIsSchema(<span class="hljs-keyword">true</span>);
processEngineConfiguration.setDatabaseSchemaUpdate(<span class="hljs-string">"no"</span>);
}

}

configure方法里的方法是为了让activiti开始时不创建也不校验activiti版本,然后在业务执行的时候都增加对应的数据库前缀,这样变相的解决了activiti的表与业务表不在同一个数据库的问题。

activiti的源码关键点在:

DbSqlSession.class中的以下方法:

public void performSchemaOperationsProcessEngineBuild() {
String databaseSchemaUpdate = Context.getProcessEngineConfiguration().getDatabaseSchemaUpdate();
if (ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate)) {
try {
dbSchemaDrop();
} catch (RuntimeException e) {
// ignore
}
}
if ( org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP.equals(databaseSchemaUpdate)
|| ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate)
|| ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_CREATE.equals(databaseSchemaUpdate)
) {
dbSchemaCreate();
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE.equals(databaseSchemaUpdate)) {
dbSchemaCheckVersion(); } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE.equals(databaseSchemaUpdate)) {
dbSchemaUpdate();
}

}


                                    </div>原文地址:https://my.oschina.net/6WiVT5YRI7U/blog/1621605
</div>
posted @
2019-06-25 17:31 
星朝 
阅读(...) 
评论(...) 
编辑 
收藏

最新文章

  1. Bjarne Stroustrup对C++程序员的忠告
  2. 类-string/Manth/Random/DateTime-及练习
  3. 2.使用Package Control组件安装
  4. BZOJ2040 : [2009国家集训队]拯救Protoss的故乡
  5. puma vs passenger vs rainbows! vs unicorn vs thin 适用场景 及 performance
  6. zookeeper适用场景:zookeeper解决了哪些问题
  7. BZOJ4143 [AMPPZ2014]The Lawyer
  8. hdu 3530 Subsequence
  9. Web CORS 跨域方式使用方式
  10. Tomcat详解
  11. HW3.2
  12. hadoop安装问题记录
  13. Android加载图片OOM错误解决方式
  14. 表单界面的兼容PC手机端解决方案
  15. nodejs异步案例
  16. tp3.2 URL_MODEL为2 配置
  17. 编写高质量代码:改善Java程序的151个建议 --[78~92]
  18. SessionState in ASP.NET Core(转载)
  19. [洛谷]p1996约瑟夫环 &amp;xdoj1311
  20. AngularJS总结

热门文章

  1. PHP--反射的方法
  2. 使用mybatis的延迟加载
  3. 【JZOJ3215】【SDOI2013】费用流
  4. IDEA maven项目查自动查看依赖关系,解决包冲突问题
  5. java reference(转)
  6. 【JZOJ4787】【NOIP2016提高A组模拟9.17】数格子
  7. fedora 安装ftp
  8. database homework3
  9. 【OI】快读
  10. Directx11教程(53) D3D11管线(8) GS的调度执行