Activity5入门案例

导入依赖

<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-spring-boot-starter-basic</artifactId>
    <version>5.21.0</version>
</dependency>
<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!-- 数据库连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.5</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
</dependency>

添加配置

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    url: jdbc:mysql://127.0.0.1:3306/crowdfunding
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver
mybatis:
  mapperLocations: classpath*:mybatis/mapper-*.xml
  typeAliasesPackage: cn.ishangit.**.bean

编写测试程序

package cn.ishangit.helloactivity5;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class HelloActivity5ApplicationTests {

    @Autowired
    private ProcessEngine processEngine ;

    @Autowired
    private RepositoryService repositoryService ;



    @Test
    public void contextLoads() {
        System.out.println( processEngine );
        System.out.println(repositoryService);
    }

}

遇到的错误1:

java.lang.NoClassDefFoundError: org/apache/ibatis/annotations/Mapper

原因:因为我们的流程框架引用的是mybatis版本与springboot-starter引用的版本不一致

解决:把activity的依赖放到springboot-starter的后面

遇到的错误2:

FileNotFoundException: class path resource [processes/] cannot be resolved to URL because it does not exist

解决:在resources目录下创建processes文件夹

遇到的错误3:

Invocation of init method failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxyatorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1708)

原因:springboot1springboot2部分自动配置类的包不同

解决:修改springboot版本为1.x的版本

结果

最后运行成功可以看到activity5框架帮我们生成了自带的25张表。

image92826f01281d26c2.png

猜你喜欢

转载自www.cnblogs.com/chen88/p/11538427.html