(四)springboot2.7.6集成activit5.23.0之更换数据源

前面学习时,使用的内存数据库H2,实际使用时,一般会替换我们指定的数据库,这个时候要怎么配置呢?

1.查看activiti-spring-boot-starter-basic的spring.factories配置。

2.查看DataSourceProcessEngineAutoConfiguration定义。

注解不是本次学习的重点,关于@AutoConfigureAfter可以查看https://zhuanlan.zhihu.com/p/157683108

3.查看DataSourceAutoConfiguration定义。

 4.查看DataSourceProperties定义。

@ConfigurationProperties(prefix = "spring.datasource")
public class DataSourceProperties implements BeanClassLoaderAware, InitializingBean {

	private ClassLoader classLoader;

	/**
	 * Whether to generate a random datasource name.
	 */
	private boolean generateUniqueName = true;

	/**
	 * Datasource name to use if "generate-unique-name" is false. Defaults to "testdb"
	 * when using an embedded database, otherwise null.
	 */
	private String name;

	/**
	 * Fully qualified name of the connection pool implementation to use. By default, it
	 * is auto-detected from the classpath.
	 */
	private Class<? extends DataSource> type;

	/**
	 * Fully qualified name of the JDBC driver. Auto-detected based on the URL by default.
	 */
	private String driverClassName;

	/**
	 * JDBC URL of the database.
	 */
	private String url;

	/**
	 * Login username of the database.
	 */
	private String username;

	/**
	 * Login password of the database.
	 */
	private String password;

	/**
	 * JNDI location of the datasource. Class, url, username and password are ignored when
	 * set.
	 */
	private String jndiName;
    
    //......
}

5.配置数据源的相关属性。

 根据上面属性定义,我们在resources目录下创建application.yml文件。并配置相关属性。

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/activiti_demo?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
    username: root
    password: **********

6.引入数据库驱动依赖。

	<dependency>
	    <groupId>mysql</groupId>
	    <artifactId>mysql-connector-java</artifactId>
	</dependency>

7.activiti流程引擎配置。

@ConfigurationProperties("spring.activiti")
public class ActivitiProperties {

  private boolean checkProcessDefinitions = true;
  private boolean jobExecutorActivate = false;
  private boolean asyncExecutorEnabled = true;
  private boolean asyncExecutorActivate = true;
  private boolean restApiEnabled;
  private String deploymentName;
  private String mailServerHost = "localhost";
  private int mailServerPort = 1025;
  private String mailServerUserName;
  private String mailServerPassword;
  private String mailServerDefaultFrom;
  private boolean mailServerUseSsl;
  private boolean mailServerUseTls;
  private String databaseSchemaUpdate = "true";
  private String databaseSchema;
  protected boolean isDbIdentityUsed = true;
  protected boolean isDbHistoryUsed = true;
  private HistoryLevel historyLevel = HistoryLevel.AUDIT;
  private String processDefinitionLocationPrefix = "classpath:/processes/";
  private List<String> processDefinitionLocationSuffixes = Arrays.asList("**.bpmn20.xml", "**.bpmn");
  private String restApiMapping = "/api/*";
  private String restApiServletName = "activitiRestApi";
  private boolean jpaEnabled = true; // true by default
  private List<String> customMybatisMappers;
  private List<String> customMybatisXMLMappers;
    //.......
}

8.配置activiti流程引擎。

一般默认就好了,有需要可以根据上面属性进行配置。

9.运行测试。

运行测试后正常。之前H2数据库使用的内存数据库,每次启动都会重新创建数据库和表,改为mysql后,只有首次运行时会自动创建25张表,之后每次启动都会启动一个twoTaskProcess流程的实例。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值