本文使用的Activiti版本为5.22.0
在使用官方提供的demo(activiti-explorer.war)时,发现其产生的记录ID与公司项目中产生的ID不同。
在查看相关配置信息时发现了如下配置:
<bean id="uuidGenerator" class="org.activiti.engine.impl.persistence.StrongUuidGenerator" /><bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">//...<property name="idGenerator" ref="uuidGenerator" />//...
</bean>
可以看到IdGenerator
接口有两个实现类DbIdGenerator
、StrongUuidGenerator
通过initIdGenerator()
可知,创建processEngineConfiguration
对象时,会判断idGenerator
是否为null
,若在创建时已经传入了idGenerator
属性,则使用外部传入的idGenerator
,否则使用DbIdGenerator
创建对象并赋值给idGenerator
属性
package org.activiti.engine.impl.persistence;import org.activiti.engine.impl.cfg.IdGenerator;import com.fasterxml.uuid.EthernetAddress;
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.TimeBasedGenerator;/*** {@link IdGenerator} implementation based on the current time and the ethernet* address of the machine it is running on.* * @author Daniel Meyer*/
public class StrongUuidGenerator implements IdGenerator {
// different ProcessEngines on the same classloader share one generator.protected static TimeBasedGenerator timeBasedGenerator;public StrongUuidGenerator() {ensureGeneratorInitialized();}protected void ensureGeneratorInitialized() {if (timeBasedGenerator == null) {synchronized (StrongUuidGenerator.class) {if (timeBasedGenerator == null) {timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());}}}}public String getNextId() {return timeBasedGenerator.generate().toString();}}
查看StrongUuidGenerator.java
文件可以发现,StrongUuidGenerator
类依赖于com.fasterxml.uuid
,对应的maven依赖如下:
<dependency><groupId>com.fasterxml.uuid</groupId><artifactId>java-uuid-generator</artifactId><version>3.1.5</version>
</dependency>
The Central Repository