1. Not using starter integration

  1. Rely on
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring</artifactId>
            <version>6.0.0</version>
        </dependency>
        <! -- Add additional dependencies if necessary -->
    Copy the code
  2. The data source
    spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
    spring.datasource.url=jdbc:mysql://localhost:3306/activiti
        ? useUnicode=true&
        characterEncoding=utf-8&
        useSSL=false&
        serverTimezone=UTC&
        nullCatalogMeansCurrent=true
    spring.datasource.username=root
    spring.datasource.password=root
    Copy the code

NullCatalogMeansCurrent =true nullCatalogMeansCurrent=true nullCatalogMeansCurrent=true nullmeanscurrent =true nullmeanscurrent =true nullmeanscurrent =true nullmeanscurrent =true nullmeanscurrent =true configuration

' 'java@Configuration Public Class ActivitiConfig {/* * Configuration is divided into the following steps * 1. Create ActivitiConfig * 2. Create ProcessEngineFactoryBean * 3. Create the ProcessEngine object with the ProcessEngineFactoryBean * 4. * */ Private Logger Logger = LoggerFactory.getLogger(ActivitiConfig.class); private final DataSource dataSource; private final PlatformTransactionManager platformTransactionManager; @Autowired public ActivitiConfig(DataSource dataSource, PlatformTransactionManager platformTransactionManager) { this.dataSource = dataSource; this.platformTransactionManager = platformTransactionManager; } /* * 1. Create a configuration file, that is, provide some configuration information, so that you can customize your own creation information * need some parameters, 1. The data source. 2. Transaction manager. * The automatic scanning of BPMN (process definition file) in the process package has also been added. So you can save the deployment / @ * * Bean public SpringProcessEngineConfiguration SpringProcessEngineConfiguration () { SpringProcessEngineConfiguration spec = new SpringProcessEngineConfiguration(); spec.setDataSource(dataSource); spec.setTransactionManager(platformTransactionManager); spec.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); Resource[] resources = null; / / start deployment process automatically try {resources = new PathMatchingResourcePatternResolver () getResources (" classpath * : process / *. BPMN "); } catch (IOException e) { e.printStackTrace(); } spec.setDeploymentResources(resources); return spec; } @Bean public ProcessEngineFactoryBean processEngine() { ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean(); processEngineFactoryBean.setProcessEngineConfiguration(springProcessEngineConfiguration()); return processEngineFactoryBean; } @Bean public RepositoryService repositoryService() throws Exception { return processEngine().getObject().getRepositoryService(); } @Bean public RuntimeService runtimeService() throws Exception { return processEngine().getObject().getRuntimeService(); } @Bean public TaskService taskService() throws Exception { return processEngine().getObject().getTaskService(); } @Bean public HistoryService historyService() throws Exception { return processEngine().getObject().getHistoryService(); }} ` ` `Copy the code
  1. Create the Process folder in Resources with the same path and name as those configured in ActivitiConfig
  2. Start the springBoot project to complete the creation

2. Use the starter

  1. Import dependence

        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter</artifactId>
            <version>7.1.0. M3.1</version>
        </dependency>
    Copy the code

    Note that the dependency version must correspond to the schema. Version version of the ACT_GE_property table in the database. Therefore, it is not recommended to change the dependency information after the table is created

  2. application.propertie

    spring.activiti.database-schema-update=true
    spring.activiti.process-definition-location-prefix=classpath:/process
    Note that if the process is followed by a /, the process definition file should be in the process folder at startup
    Note the statement added at the end of the url
    
    spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
    spring.datasource.url=jdbc:mysql://localhost:3306/activiti? useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&nullCatalogMeansCurrent=true
    spring.datasource.username=root
    spring.datasource.password=root
    Copy the code
  3. Create the required folder under the Resources folder

  4. Start, and you can see that the corresponding table information is created in the database

There is a flaw in this scheme. By default, you do not create a table for history and need to configure it manually in application.properties