项目场景:
项目需要使用camunda,因为多数据源,需要把业务数据源作为主数据源, 所以,有了camunda多数据源配置的要求
问题描述
感谢陈无问作者的解决方案
camunda日常操作
但是根据作者提供代码配置完成后,启动的时候报错了
如下所示:
Caused by: org.camunda.bpm.engine.ProcessEngineException: historyLevel mismatch: configuration says HistoryLevelAudit(name=audit, id=2) and database says HistoryLevelFull(name=full, id=3)
at org.camunda.bpm.engine.impl.HistoryLevelSetupCommand.execute(HistoryLevelSetupCommand.java:60) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.impl.HistoryLevelSetupCommand.execute(HistoryLevelSetupCommand.java:34) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:28) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:110) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:70) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.impl.interceptor.CommandCounterInterceptor.execute(CommandCounterInterceptor.java:35) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.impl.interceptor.ExceptionCodeInterceptor.execute(ExceptionCodeInterceptor.java:55) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.impl.ProcessEngineImpl.executeSchemaOperations(ProcessEngineImpl.java:148) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:110) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:1104) ~[camunda-engine-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:55) ~[camunda-engine-spring-7.19.0.jar:7.19.0]
at org.camunda.bpm.engine.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:34) ~[camunda-engine-spring-7.19.0.jar:7.19.0]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169) ~[spring-beans-5.3.25.jar:5.3.25]
... 52 common frames omitted
原因分析:
百度了一番没找到对应的解决方案,所以又开始仔细研究了这句话:
首先HistoryLevel是一个配置流程历史记录级别
大概意思就是说configuration中配置的HistoryLevelAudit是audit
而数据库中HistoryLevelAudit配置的是full
解决方案:
super.historyLevel = HistoryLevel.HISTORY_LEVEL_FULL;
再初始化的时候,增加了这么一句配置,就好了
@Configuration
public class MyCamundaProcessEngineConfiguration extends StandaloneProcessEngineConfiguration {
@Value("${camunda.db.url}")
private String jdbcUrl;
@Value("${camunda.db.username}")
private String jdbcUsername;
@Value("${camunda.db.password}")
private String jdbcPassword;
@Value("${camunda.db.driver}")
private String jdbcDriver;
public MyCamundaProcessEngineConfiguration() {
// 没有camunda表时自动建表
super.databaseSchemaUpdate = "true";
super.historyLevel = HistoryLevel.HISTORY_LEVEL_FULL;
//增加了这句配置,就好了
}
@Override
protected void initDataSource() {
super.jdbcDriver = jdbcDriver;
super.jdbcUrl = jdbcUrl;
super.jdbcUsername = jdbcUsername;
super.jdbcPassword = jdbcPassword;
super.initDataSource();
}
}