中间也是遇到了很多的坑,不过都以及通过百度和自己思考解决了,看了网上的教程和相关笔记,大家普遍都是和黑马一样,用的Mysql5.7版本,我本地的Mysql是8.0的,懒得去换版本了,我就想着霸王硬上弓,谁知道里面的问题还是挺多的
说实话,看了网上这么多相关的内容,全部清一色是mysql5.7的,这对我一个8.0的靓仔非常的不友好啊,能查到的东西有限,所以如果你也是8.0的,希望在面对遇到这些问题的时候本文能够帮助到您,这也是我的初衷
1 Spring框架 2 Mysql(8.0) 3 Maven 4 Activiti(7.0) 5 Junit单元测试
maven项目也不是不行
我把全部的pom都放进去了,大家根据自己的需求自取
注意:我数据库是8.0的,所以用的依赖也是8.0的,如果你本地是5.7的,记得更换版本哦,不然会报下面这个错,我单独出了个文章
- <project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0modelVersion>
-
- <groupId>com.examplegroupId>
- <artifactId>ActicitiSpringDemoartifactId>
- <version>1.0-SNAPSHOTversion>
- <properties>
- <slf4j.version>1.6.6slf4j.version>
- <log4j.version>1.2.12log4j.version>
- properties>
- <dependencies>
- <dependency>
- <groupId>org.activitigroupId>
- <artifactId>activiti-engineartifactId>
- <version>7.0.0.Beta1version>
- dependency>
- <dependency>
- <groupId>org.activitigroupId>
- <artifactId>activiti-springartifactId>
- <version>7.0.0.Beta1version>
- dependency>
- <dependency>
- <groupId>org.activitigroupId>
- <artifactId>activiti-bpmn-modelartifactId>
- <version>7.0.0.Beta1version>
- dependency>
- <dependency>
- <groupId>org.activitigroupId>
- <artifactId>activiti-bpmn-converterartifactId>
- <version>7.0.0.Beta1version>
- dependency>
- <dependency>
- <groupId>org.activitigroupId>
- <artifactId>activiti-json-converterartifactId>
- <version>7.0.0.Beta1version>
- dependency>
- <dependency>
- <groupId>org.activitigroupId>
- <artifactId>activiti-bpmn-layoutartifactId>
- <version>7.0.0.Beta1version>
- dependency>
- <dependency>
- <groupId>org.activiti.cloudgroupId>
- <artifactId>activiti-cloud-services-apiartifactId>
- <version>7.0.0.Beta1version>
- dependency>
- <dependency>
- <groupId>aspectjgroupId>
- <artifactId>aspectjweaverartifactId>
- <version>1.5.4version>
- dependency>
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <version>8.0.18version>
- dependency>
- <dependency>
- <groupId>junitgroupId>
- <artifactId>junitartifactId>
- <version>4.12version>
- dependency>
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-testartifactId>
- <version>5.0.7.RELEASEversion>
- dependency>
-
- <dependency>
- <groupId>log4jgroupId>
- <artifactId>log4jartifactId>
- <version>${log4j.version}version>
- dependency>
- <dependency>
- <groupId>org.slf4jgroupId>
- <artifactId>slf4j-apiartifactId>
- <version>${slf4j.version}version>
- dependency>
- <dependency>
- <groupId>org.slf4jgroupId>
- <artifactId>slf4j-log4j12artifactId>
- <version>${slf4j.version}version>
- dependency>
- <dependency>
- <groupId>org.slf4jgroupId>
- <artifactId>slf4j-nopartifactId>
- <version>${slf4j.version}version>
- dependency>
-
- <dependency>
- <groupId>org.mybatisgroupId>
- <artifactId>mybatisartifactId>
- <version>3.4.5version>
- dependency>
- <dependency>
- <groupId>commons-dbcpgroupId>
- <artifactId>commons-dbcpartifactId>
- <version>1.4version>
- dependency>
- dependencies>
-
- <build>
- <plugins>
- plugins>
- build>
- project>
在你的resources目录下创建activiti-spring.xml 当然名字不是固定的,不管一会测试的时候需要对上
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd">
-
-
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
- <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
- <property name="url" value="jdbc:mysql://localhost:3306/activitispring?useUnicode=true&characterEncoding=utf8&nullCatalogMeansCurrent=true&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC"/>
- <property name="username" value="root"/>
- <property name="password" value="root"/>
- <property name="maxActive" value="3" />
- <property name="maxIdle" value="1" />
- bean>
-
-
-
- <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
-
- <property name="dataSource" ref="dataSource"/>
-
- <property name="transactionManager" ref="transactionManager"/>
-
-
-
- <property name="databaseSchemaUpdate" value="true"/>
- bean>
-
- <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
- <property name="processEngineConfiguration" ref="processEngineConfiguration"/>
- bean>
-
- <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
-
- <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
-
- <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
-
- <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
-
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"/>
- bean>
-
- <tx:advice id="txAdvice" transaction-manager="transactionManager">
- <tx:attributes>
-
- <tx:method name="save*" propagation="REQUIRED"/>
- <tx:method name="insert*" propagation="REQUIRED"/>
- <tx:method name="delete*" propagation="REQUIRED"/>
- <tx:method name="update*" propagation="REQUIRED"/>
- <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
- <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
- tx:attributes>
- tx:advice>
-
- beans>
这个地方主要需要注意的地方有点多,也是我耗时最长的地方
第一:你的驱动信息,根据版本的不同驱动也不同,8.0需要多加个cj
第二:数据库的url的一些参数,我这个是比较完整的,帮大伙踩过坑了,缺的参数报的错我都查过了,如果你遇到什么问题,根据日志报错信息去查,肯定可以解决
对于mysql-connector-java版本 ≥ 8.x,需在数据库访问的地址上添加一个非常重要的参数信息:nullCatalogMeansCurrent=true
如果不加就会报下面类似的错误,这就会给你一种幻觉,明明日志已经查到了,但是为什么提示不存在呢?
‘myactiviti.act_ge_property’ doesn’t exist,创建表不成功时遇到。为什么创建不成功,因为mysql使用schema标识库名而不是catalog,因此mysql会扫描所有的库来找表,如果其他库中有相同名称的表,activiti就以为找到了,本质上这个表在当前数据库中并不存在,我本地有一个另外的库,里面存在25张activiti相关的表,我想可能是查到那个库里面了,这个错误非常坑,谨记!
在xml中用&拼接url参数也是不行的,牵扯到一个转义问题,具体参考我这篇文章
Mybatis xml文件中&出现报错问题:Unescaped & or nonterminated character/entity reference_不允许摆烂的博客-CSDN博客
第三:因为我们把配置信息交给了spring,spring启动加载的时候会根据我们的配置创建25张表,这里我们指名了数据库名,所以需要提前准备好一个库
以上都处理完成了,那么就可以写代码测试了 一个简单的单元测试
- package com.wyh;
-
- import org.activiti.engine.RepositoryService;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations = "classpath:activiti-spring.xml")
- public class ActivitiSpringTest {
-
- @Autowired
- private RepositoryService repositoryService;
-
- @Test
- public void testRep(){
- System.out.println(repositoryService);
- }
- }
如果能输出内容,且数据库里面创建了25张表,那么这样简单的测试以及spring整合Activiti就算成功了
来一个完整的项目目录吧,省的有的同学迷路
还有学习了一些简单的Activiti的API,以及使用IDEA插件自定义流程图,并审批或拒签,这些后面再出一些文章去介绍吧,晚安打工人