You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何在Spring Boot Activiti项目中全局启用UUID作为流程ID?

Configuring UUID ID Generation for Activiti in Spring Boot

Great question! When working with Spring Boot + Activiti, you don't have to create an activiti.cfg.xml file to enable UUIDs for your process IDs. Spring Boot's auto-configuration provides cleaner, more integrated alternatives. Here are your best options:

Option 1: Define a Spring Bean (Most Flexible)

Activiti automatically detects and uses any Spring Bean of type IdGenerator in your application context. This is the most flexible approach, especially if you ever need to customize the ID generation logic later.

Just create a configuration class and define the StrongUuidGenerator as a bean:

import org.activiti.engine.impl.persistence.StrongUuidGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ActivitiIdGeneratorConfig {

    @Bean
    public StrongUuidGenerator strongUuidGenerator() {
        return new StrongUuidGenerator();
    }
}

Activiti will pick up this bean automatically—no extra XML or properties needed.

Option 2: Use Spring Boot Configuration Properties

If you prefer a configuration-file-only approach, many recent versions of the Activiti Spring Boot Starter let you set the ID generator directly in application.properties or application.yml:

For application.properties:

activiti.id-generator=org.activiti.engine.impl.persistence.StrongUuidGenerator

For application.yml:

activiti:
  id-generator: org.activiti.engine.impl.persistence.StrongUuidGenerator

Note: Double-check your Activiti Spring Boot Starter version—this property is supported in most 7.x releases and later.

Do You Need activiti.cfg.xml?

Short answer: No. The above Spring Boot-native approaches are designed to replace the traditional XML configuration file. Using beans or properties aligns better with Spring Boot's convention-over-configuration philosophy and keeps your setup more maintainable.

Recommendation

  • Go with the Spring Bean approach if you want maximum flexibility (e.g., adding custom logic to the ID generator down the line).
  • Use the configuration property approach for a quick, no-code setup if you just need to enable UUIDs out of the box.

内容的提问来源于stack exchange,提问作者Learner

火山引擎 最新活动