Activiti之act_ge_property表引发的坑(dbSchemaUpdate)
参考文档:
https://blog.csdn.net/lb19921223/article/details/79213851
上篇文章写道,我学习acitiviti的时候,使用mysql的truncate把表中的数据都删除了,然后重新部署流程,结果居然报错了。
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 流程引擎配置的bean --> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/db_activiti?serverTimezone=Asia/Shanghai" /> <property name="jdbcDriver" value="com.mysql.cj.jdbc.Driver" /> <property name="jdbcUsername" value="root" /> <property name="jdbcPassword" value="123456" /> <property name="databaseSchemaUpdate" value="true" /> </bean> </beans>
package com.yuanqiao.first_activiti.deployment; import java.util.List; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngines; import org.activiti.engine.RepositoryService; import org.activiti.engine.repository.Deployment; import org.activiti.engine.repository.DeploymentBuilder; import org.activiti.engine.repository.ProcessDefinition; import org.junit.Test; import com.google.gson.Gson; /** * 通过读取bpmn文件,来部署流程图 * * @author yuanqiao * */ public class DeploymentProcess { @Test public void deploymentFirstProcess() { ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().addClasspathResource("first.bpmn"); Deployment deployment = deploymentBuilder.deploy(); String deploymentId = deployment.getId(); System.out.println(deploymentId); List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery() .deploymentId(deploymentId).list(); Gson gson = new Gson(); System.out.println(gson.toJson(processDefinitionList)); } }
java.lang.NullPointerException
at org.activiti.engine.impl.db.DbSqlSession.dbSchemaUpdate(DbSqlSession.java:911)
at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:1318)
at org.activiti.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:28)
at org.activiti.engine.impl.interceptor.CommandInvoker$1.run(CommandInvoker.java:37)
at org.activiti.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:78)
at org.activiti.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:57)
at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:42)
at org.activiti.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:48)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:63)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:29)
at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:44)
at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:81)
at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:665)
at org.activiti.engine.ProcessEngines.buildProcessEngine(ProcessEngines.java:189)
at org.activiti.engine.ProcessEngines.initProcessEngineFromResource(ProcessEngines.java:162)
at org.activiti.engine.ProcessEngines.init(ProcessEngines.java:94)
at org.activiti.engine.ProcessEngines.getProcessEngine(ProcessEngines.java:223)
at org.activiti.engine.ProcessEngines.getDefaultProcessEngine(ProcessEngines.java:212)
at com.yuanqiao.first_activiti.deployment.DeploymentProcess.deploymentFirstProcess(DeploymentProcess.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
解决办法如下:
最近给客户部署系统,系统中使用Activiti流程引擎,启动Tomcat死活报错,报错如上边信息。真是一头雾水,刚开始以为是程序自身或者服务器环境问题(因为环境都是新装的),没往流程引擎上想。
上边的异常只是截取的最关键的地方,其实在这之前还要报一片异常,把环境和程序配置检查了一便,还是无果,最终把焦点集中在了org.activiti.engine.impl.db.DbSqlSession.dbSchemaUpdate,意思是流程表在更新表结构的时候出现异常,怎么会老是更新呢?查看了Activiti的配置,如上图。
databaseSchemaUpdate设置为true代表如果没有表,则自动创建表;估计是这里的原因,我重新建了一个空的数据库test1,然后程序连上test1数据库,启动tomcat,竟然成功了。成功了,心里的一块石头落了地。
但是还是感觉很奇怪,不知道真正原因是什么,后来才想到,act_ge_property表,该表是流程引擎的属性表,里面的三条数据是基础数据,不可以删除。而我看了一下数据库初始化sql,竟然没有这三条数据,我这才恍然大悟,我准备程序包的时候,为了不把流程里面的数据带过来,我只是导出的表结构,没有导出数据。也就是说还原到服务器数据库的时候,act_ge_property表里面压根没有数据,这就造成了当前这个问题。聪明反被聪明误。。以后引以为戒吧。
总结:部署程序准备数据库初始化sql时,对于流程表,以后就不要导出来,只导出业务表,流程表让系统启动时自己生成去。