流程引擎配置
starter 使用org.camunda.bpm.engine.impl.cfg.ProcessEnginePlugin
机制来配置引擎。
配置分为 sections 。 这些 sections 被如下接口定义:
org.camunda.bpm.spring.boot.starter.configuration.CamundaProcessEngineConfiguration
org.camunda.bpm.spring.boot.starter.configuration.CamundaDatasourceConfiguration
org.camunda.bpm.spring.boot.starter.configuration.CamundaHistoryConfiguration
org.camunda.bpm.spring.boot.starter.configuration.CamundaHistoryLevelAutoHandlingConfiguration
org.camunda.bpm.spring.boot.starter.configuration.CamundaJobConfiguration
org.camunda.bpm.spring.boot.starter.configuration.CamundaDeploymentConfiguration
org.camunda.bpm.spring.boot.starter.configuration.CamundaJpaConfiguration
org.camunda.bpm.spring.boot.starter.configuration.CamundaAuthorizationConfiguration
org.camunda.bpm.spring.boot.starter.configuration.CamundaFailedJobConfiguration
org.camunda.bpm.spring.boot.starter.configuration.CamundaMetricsConfiguration
默认配置
以下是启动器提供的默认配置和最佳实践配置,可以自定义或重写。
DefaultProcessEngineConfiguration
设置流程引擎的名称,并自动添加所有 ProcessEnginePlugin
beans 到配置中。
DefaultDatasourceConfiguration
配置Camunda数据源并启用事务集成。 默认情况下,主 DataSource
和 PlatformTransactionManager
beans 通过流程引擎配置连接。
如果要配置多个数据源
而且不想将 @Primary
用于使用流程引擎,那么你可以使用名称创建单独的数据源 camundaBpmDataSource
这将由Camunda自动连接。
@Bean
@Primary
@ConfigurationProperties(prefix="datasource.primary")
public DataSource primaryDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name="camundaBpmDataSource")
@ConfigurationProperties(prefix="datasource.secondary")
public DataSource secondaryDataSource() {
return DataSourceBuilder.create().build();
}
如果你不想使用@Primary
事务管理器,可以创建一个单独的事务管理器,名称为camundaBpmTransactionManager
,它将与用于Camunda的数据源(@Primary
或camundaBpmDataSource
)连接。
@Bean
@Primary
public PlatformTransactionManager primaryTransactionManager() {
return new JpaTransactionManager();
}
@Bean(name="camundaBpmTransactionManager")
public PlatformTransactionManager camundaTransactionManager(@Qualifier("camundaBpmDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
数据源和事务管理器的beans必须匹配,即确保事务管理器实际管理着Camunda数据源。如果不是这样,流程引擎将对数据源连接使用自动提交模式,可能会导致数据库中的不一致。
DefaultHistoryConfiguration
配置应用于流程引擎的历史配置。如果没有配置,则使用历史级别FULL。
如果你想使用一个自定义的HistoryEventHandler
,你只需要提供一个实现接口的bean。
@Bean
public HistoryEventHandler customHistoryEventHandler() {
return new CustomHistoryEventHanlder();
}
DefaultHistoryLevelAutoHandlingConfiguration
由于camunda版本>=7.4支持自动历史级别
,这个配置增加了对<=7.3版本的支持。
为了对处理有更多的控制,你可以提供你自己的
org.camunda.bpm.spring.boot.starter.jdbc.HistoryLevelDeterminator
名为historyLevelDeterminator
。
重要提示:默认配置会在所有其他默认配置之后使用排序机制进行应用。
DefaultJobConfiguration
将Job执行属性应用于流程引擎。
为了对执行本身有更多的控制,你可以提供你自己的
org.camunda.bpm.engine.impl.jobexecutor.JobExecutor
org.springframework.core.task.TaskExecutor
名为camundaTaskExecutor
重要提示:Job执行器在配置中没有被启用。
这是在spring context成功加载后启动的 (see org.camunda.bpm.spring.boot.starter.runlistener
).
DefaultDeploymentConfiguration
如果启用了自动部署(默认情况下是这样的),在classpath中发现的所有进程都会被部署。 资源模式可以通过属性来改变(见 properties).
DefaultJpaConfiguration
如果JPA被启用并且配置了一个entityManagerFactory
bean,那么流程引擎就会被启用以使用JPA(见properties)。
DefaultAuthorizationConfiguration
将授权配置应用于流程引擎。如果没有配置,则使用 “camunda” 的默认值(见properties)。
覆盖默认的配置
提供一个实现标记接口之一的Bean。例如,自定义数据源的配置。
@Configuration
public class MyCamundaConfiguration {
@Bean
public static CamundaDatasourceConfiguration camundaDatasourceConfiguration() {
return new MyCamundaDatasourceConfiguration();
}
}
添加额外的配置
你只需要提供一个或多个实现org.camunda.bpm.engine.impl.cfg.ProcessEnginePlugin
接口的bean(或者org.camunda.bpm.spring.boot.starter.configuration.impl.AbstractCamundaConfiguration
扩展)。
配置的应用是通过spring的排序机制(@Order
注解和Ordered
接口)进行排序。
因此,如果你希望你的配置在默认配置之前被应用,请在你的类中添加@Order(Ordering.DEFAULT_ORDER - 1)
注解。
如果你想让你的配置在默认配置之后应用,请在你的类中添加一个@Order(Order.DEFAULT_ORDER + 1)
注解。
@Configuration
public class MyCamundaConfiguration {
@Bean
@Order(Ordering.DEFAULT_ORDER + 1)
public static ProcessEnginePlugin myCustomConfiguration() {
return new MyCustomConfiguration();
}
}
Or, if you have component scan enabled:
@Component
@Order(Ordering.DEFAULT_ORDER + 1)
public class MyCustomConfiguration implements ProcessEnginePlugin {
@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
//...
}
...
}
or
@Component
@Order(Ordering.DEFAULT_ORDER + 1)
public class MyCustomConfiguration extends AbstractCamundaConfiguration {
@Override
public void preInit(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
//...
}
...
}
Camunda 引擎特性
除了基于Bean的覆盖流程引擎配置属性的方式之外,也可以通过application.yaml
配置文件来设置这些属性。关于如何使用它的说明可以在 Spring Boot Starter 向导中找到。
可用的特性如下:
Prefix | Property name | Description | Default value |
---|---|---|---|
General | |||
camunda.bpm |
.enabled |
Switch to disable the Camunda auto-configuration. Use to exclude Camunda in integration tests. | true |
.process-engine-name |
Name of the process engine | Camunda default value | |
.generate-unique-process-engine-name |
Generate a unique name for the process engine (format: 'processEngine' + 10 random alphanumeric characters) | false | |
.generate-unique-process-application-name |
Generate a unique Process Application name for every Process Application deployment (format: 'processApplication' + 10 random alphanumeric characters) | false | |
.default-serialization-format |
Default serialization format | Camunda default value | |
.history-level |
Camunda history level | FULL | |
.history-level-default |
Camunda history level to use when history-level is auto , but the level can not determined automatically |
FULL | |
.auto-deployment-enabled |
If processes should be auto deployed. This is disabled when using the SpringBootProcessApplication | true |
|
.default-number-of-retries |
Specifies how many times a job will be executed before an incident is raised | 3 |
|
.job-executor-acquire-by-priority |
If set to true, the job executor will acquire the jobs with the highest priorities | false |
|
.license-file |
Provides a URL to your Camunda license file and is automatically inserted into the DB when the application starts (but only if no valid license key is found in the DB). Note: This property is only available when using the camunda-bpm-spring-boot-starter-webapp-ee | By default, the license key will be loaded:
|
|
.id-generator |
Configure idGenerator. Allowed values: simple , strong , prefixed . prefixed id generator is like strong , but uses a Spring application name (${spring.application.name} ) as the prefix for each id. |
strong |
|
.version |
Version of the process engine | Read only value, e.g., 7.4.0 | |
.formatted-version |
Formatted version of the process engine | Read only value, e.g., (v7.4.0) | |
.deployment-resource-pattern |
Location for auto deployment | classpath*:**/*.bpmn, classpath*:**/*.bpmn20.xml, classpath*:**/*.dmn, classpath*:**/*.dmn11.xml, classpath*:**/*.cmmn, classpath*:**/*.cmmn10.xml, classpath*:**/*.cmmn11.xml |
|
Job Execution | |||
camunda.bpm.job-execution |
.enabled |
If set to false , no JobExecutor bean is created at all. Maybe used for testing. |
true |
.deployment-aware |
If job executor is deployment aware | false |
|
.core-pool-size |
Set to value > 1 to activate parallel job execution. | 3 |
|
.keep-alive-seconds |
Specifies the time, in milliseconds, for which threads are kept alive when there are no more tasks present. When the time expires, threads are terminated so that the core pool size is reached. | 0 |
|
.lock-time-in-millis |
Specifies the time in milliseconds an acquired job is locked for execution. During that time, no other job executor can acquire the job. | 300000 |
|
.max-jobs-per-acquisition |
Sets the maximal number of jobs to be acquired at once. | 3 |
|
.max-pool-size |
Maximum number of parallel threads executing jobs. | 10 |
|
.queue-capacity |
Sets the size of the queue which is used for holding tasks to be executed. | 3 |
|
.wait-time-in-millis |
Specifies the wait time of the job acquisition thread in milliseconds in case there are less jobs available for execution than requested during acquisition. If this is repeatedly the case, the wait time is increased exponentially by the factor waitIncreaseFactor . The wait time is capped by maxWait . |
5000 |
|
.max-wait |
Specifies the maximum wait time of the job acquisition thread in milliseconds in case there are less jobs available for execution than requested during acquisition. | 60000 |
|
.backoff-time-in-millis |
Specifies the wait time of the job acquisition thread in milliseconds in case jobs were acquired but could not be locked. This condition indicates that there are other job acquisition threads acquiring jobs in parallel. If this is repeatedly the case, the backoff time is increased exponentially by the factor waitIncreaseFactor . The time is capped by maxBackoff . With every increase in backoff time, the number of jobs acquired increases by waitIncreaseFactor as well. |
0 |
|
.max-backoff |
Specifies the maximum wait time of the job acquisition thread in milliseconds in case jobs were acquired but could not be locked. | 0 |
|
.backoff-decrease-threshold |
Specifies the number of successful job acquisition cycles without a job locking failure before the backoff time is decreased again. In that case, the backoff time is reduced by waitIncreaseFactor . |
100 |
|
.wait-increase-factor |
Specifies the factor by which wait and backoff time are increased in case their activation conditions are repeatedly met. | 2 |
|
Datasource | |||
camunda.bpm.database |
.schema-update |
If automatic schema update should be applied, use one of [true, false, create, create-drop, drop-create] | true |
.type |
Type of the underlying database. Possible values: h2 , mysql, mariadb, oracle, postgres, mssql, db2. |
Will be automatically determined from datasource | |
.table-prefix |
Prefix of the camunda database tables. Attention: The table prefix will not be applied if you are using schema-update ! |
Camunda default value | |
.schema-name |
The dataBase schema name | Camunda default value | |
.jdbc-batch-processing |
Controls if the engine executes the jdbc statements as Batch or not. It has to be disabled for some databases. See the user guide for further details. | Camunda default value: true | |
Eventing | |||
camunda.bpm.eventing |
.execution |
Enables eventing of delegate execution events. See the user guide for further details. | true |
.history |
Enables eventing of history events. See the user guide for further details. | true |
|
.task |
Enables eventing of task events. See the user guide for further details. | true |
|
JPA | |||
camunda.bpm.jpa |
.enabled |
Enables jpa configuration | true . Depends on entityManagerFactory bean. |
.persistence-unit-name |
JPA persistence unit name | - | |
.close-entity-manager |
Close JPA entity manager | true |
|
.handle-transaction |
JPA handle transaction | true |
|
Management | |||
camunda.bpm.management |
.health.camunda.enabled |
Enables default camunda health indicators | true |
Metrics | |||
camunda.bpm.metrics |
.enabled |
Enables metrics reporting | Camunda default value |
.db-reporter-activate |
Enables db metrics reporting | Camunda default value | |
Webapp | |||
camunda.bpm.webapp |
.enabled |
Switch to disable the Camunda Webapp auto-configuration. | true |
.index-redirect-enabled |
Registers a redirect from / to camunda's bundled index.html .
If this property is set to false , the
default
Spring Boot behaviour is taken into account. |
true |
|
.application-path |
Changes the application path of the webapp.
When setting to / , the legacy behavior of Camunda Spring Boot Starter <= 3.4.x is restored.
|
/camunda |
|
camunda.bpm.webapp.csrf |
|||
.target-origin |
Sets the application expected deployment domain. See the user guide for details. | Not set | |
.deny-status |
Sets the HTTP response status code used for a denied request. See the user guide for details. | 403 |
|
.random-class |
Sets the name of the class used to generate tokens. See the user guide for details. | java.security.SecureRandom |
|
.entry-points |
Sets additional URLs that will not be tested for the presence of a valid token. See the user guide for details. | Not set | |
.enable-secure-cookie |
If set to true , the cookie flag Secure is enabled.
|
false |
|
.enable-same-site-cookie |
If set to false , the cookie flag SameSite is disabled. The default value of the SameSite cookie is LAX and it can be changed via same-site-cookie-option configuration property.
|
true |
|
.same-site-cookie-option |
Can be configured either to STRICT or LAX .Note:
|
Not set | |
.same-site-cookie-value |
A custom value for the cookie property. Note:
|
Not set | |
.cookie-name |
A custom value to change the cookie name. Note: Please make sure to additionally change the cookie name for each webapp (e. g. Cockpit ) separately. |
XSRF-TOKEN |
|
camunda.bpm.webapp.header-security |
|||
.xss-protection-disabled |
The header can be entirely disabled if set to true . Allowed set of values is true and false .
|
false |
|
.xss-protection-option |
The allowed set of values:
|
BLOCK |
|
.xss-protection-value |
A custom value for the header can be specified. Note:
|
1; mode=block |
|
.content-security-policy-disabled |
The header can be entirely disabled if set to true . Allowed set of values is true and false .
|
false |
|
.content-security-policy-value |
A custom value for the header can be specified. Note: Property is ignored when .content-security-policy-disabled is set to true
|
base-uri 'self' |
|
.content-type-options-disabled |
The header can be entirely disabled if set to true . Allowed set of values is true and false .
|
false |
|
.content-type-options-value |
A custom value for the header can be specified. Note: Property is ignored when .content-security-policy-disabled is set to true
|
nosniff |
|
.hsts-disabled |
Set to false to enable the header. The header is disabled by default.Allowed set of values is true and false .
|
true |
|
.hsts-max-age |
Amount of seconds, the browser should remember to access the webapp via HTTPS. Note:
|
31536000 |
|
.hsts-include-subdomains-disabled |
HSTS is additionally to the domain of the webapp enabled for all its subdomains. Note:
|
true |
|
.hsts-value |
A custom value for the header can be specified. Note:
|
max-age=31536000 |
|
Authorization | |||
camunda.bpm.authorization |
.enabled |
Enables authorization | Camunda default value |
.enabled-for-custom-code |
Enables authorization for custom code | Camunda default value | |
.authorization-check-revokes |
Configures authorization check revokes | Camunda default value | |
.tenant-check-enabled |
Performs tenant checks to ensure that an authenticated user can only access data that belongs to one of his tenants. | true |
|
Admin User | |||
camunda.bpm.admin-user |
.id |
The username (e.g., 'admin') | - |
.password |
The initial password | =id |
|
.firstName , .lastName , .email |
Additional (optional) user attributes | Defaults to value of 'id' | |
Filter | |||
camunda.bpm.filter |
.create |
Name of a "show all" filter. If set, a new filter is created on start that displays all tasks. Useful for testing on h2 db. | - |
通用属性
上面描述的配置方法并没有涵盖所有可用的流程引擎属性。要覆盖任何未公开的流程引擎配置属性(即上面列出的),你可以使用generic-perties。
camunda:
bpm:
generic-properties:
properties:
...
笔记:
使用generic-properties
关键字重写一个已经公开的属性不会影响流程引擎的配置。所有公开的属性只能用其公开的标识符来重写。
案例
使用公开的属性重写配置:
camunda.bpm:
admin-user:
id: kermit
password: superSecret
firstName: Kermit
filter:
create: All tasks
使用通用属性覆盖配置。
camunda:
bpm:
generic-properties:
properties:
enable-password-policy: true
Session Cookie
你可以通过application.yaml
配置文件为Spring Boot应用程序配置 *Session Cookie*。
Camunda Spring Boot Starter版本:
<= 2.3 (Spring Boot version 1.x)
server:
session:
cookie:
secure: true
http-only: true # 在 1.5.14 版本之前不可用
>= 3.0 (Spring Boot version 2.x)
server:
servlet:
session:
cookie:
secure: true
http-only: true # 在 2.0.3 版本之前不可用
配置 Spin 数据格式
当在classpath上检测到camunda-spin-dataformat-jon-jackson
依赖时,Camunda Spring Boot Starter会自动配置Spin Jackson Json DataFormat。
camunda-spin-dataformat-jon-jackson
的依赖关系时,就会自动配置Spin Jackson Json数据格式。要包含一个
DataFormatConfigurator
的所需Jackson Java 8模块,适当的依赖也需要包含在classpath中。请注意,camunda-engine-plugin-spin
也需要作为一个依赖项被包含,以便自动配置器能够工作。
自动配置目前支持以下Jackson Java 8模块:
- Parameter names (
jackson-module-parameter-names
) - Java 8 Date/time (
jackson-datatype-jdk8
) - Java 8 Datatypes (
jackson-datatype-jsr310
)
小心!
当使用camunda-spin-dataformat-all
作为依赖时,Spin Jackson Json DataFormat的自动配置被禁用。camunda-spin-dataformat-all
工件会覆盖Jackson库,这破坏了与普通Jackson模块的兼容性。如果有必要使用camunda-spin-dataformat-all
,请使用Spin Custom DataFormat configuration的标准方法。
例如,为了在Spin中提供对Java 8日期/时间类型的支持,需要在Spring Boot应用程序的pom.xml
文件中添加以下依赖,以及相应的版本标记。
<dependencies>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine-plugin-spin</artifactId>
</dependency>
<dependency>
<groupId>org.camunda.spin</groupId>
<artifactId>camunda-spin-dataformat-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
</dependencies>
Spring Boot还提供了一些不错的配置属性,以进一步配置Jackson ObjectMapper
。它们可以在这里找到。
为了提供额外的配置,需要进行以下操作。
- 提供一个`org.camunda.spin.spi.DataFormatConfigurator’的自定义实现。
- 在
META-INF/spring.plants
文件中添加接口和实现的全限定类名的适当键值对。 - 确保包含配置器的组件可以从Spin的classloader中到达。