SpringBoot and Activiti7 integration (a)

Recently the company To the original old system out of service migration, involving things workflow, the new system set workflow with Activiti, so start learning Activiti, and recording learning, problems encountered and solutions.

Add dependent

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter</artifactId>
            <version>7.1.0.M4</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

Profiles

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: 123456
    url: jdbc:mysql://127.0.0.1:3306/activiti?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
  activiti:
    check-process-definitions: true #自动检查、部署流程定义文件
    database-schema-update: true  #自动更新数据库结构

Note here with a jar activiti version is 7.1.0.M4 , then start the service can be generated directly related to the 17 table.

History does not generate a default table, if needed history table, spring.activiti add configuration

spring:
  activiti:
    check-process-definitions: true #自动检查、部署流程定义文件
    database-schema-update: true  #自动更新数据库结构
    db-history-used: true
    history-level: full
  • ACT_RE_ : RE representatives repository. With this prefix table contains static information *, for example, process definitions and process resources (images, rules, etc.).
  • ACT_RU_ : RU * representatives runtime. These run time table, which includes the runtime process instance data, user tasks, variables, and other operations. Activiti is performed only during runtime data stored in the process instance, and delete records at the end of the process instance. When the table is small and fast so it can make the run.
  • ACT_HI_ : HI * representatives history. These tables contain historical data such as past process instances, variables, tasks, and so on.
  • ACT_GE_ *: generaldata, for a variety of use cases.

If you use depends on the latest activiti-spring-boot-starter 7.1.0.M5 version , start the error:

Parameter 0 of method userGroupManager in org.activiti.core.common.spring.identity.config.ActivitiSpringIdentityAutoConfiguration required a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' that could not be found.

The following candidates were found but could not be injected:
    - Bean method 'inMemoryUserDetailsManager' in 'UserDetailsServiceAutoConfiguration' not loaded because @ConditionalOnBean did not find required type 'org.springframework.security.config.annotation.ObjectPostProcessor'

Because of SpringSecurity according Two Internet troubleshooting configuration

@SpringBootApplication(exclude = {
        SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class
})
public class SpringbootAcitvitiApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootAcitvitiApplication.class, args);
    }

}

This method is ineffective, however, there is a SecurityAutoConfiguration.class with activiti package, but this version of the jar package does not have this class.

Solution pom.xml added

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

Add File cases of official

/*
 * Copyright 2018 Alfresco, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.wx.springboot_acitviti.scutity;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Configuration
@EnableWebSecurity
public class DemoApplicationConfiguration extends WebSecurityConfigurerAdapter {

    private Logger logger = LoggerFactory.getLogger(DemoApplicationConfiguration.class);

    @Override
    @Autowired
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(myUserDetailsService());
    }

    @Bean
    public UserDetailsService myUserDetailsService() {

        InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager();

        String[][] usersGroupsAndRoles = {
                {"salaboy", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"},
                {"ryandawsonuk", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"},
                {"erdemedeiros", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"},
                {"other", "password", "ROLE_ACTIVITI_USER", "GROUP_otherTeam"},
                {"admin", "password", "ROLE_ACTIVITI_ADMIN"},
        };

        for (String[] user : usersGroupsAndRoles) {
            List<String> authoritiesStrings = Arrays.asList(Arrays.copyOfRange(user, 2, user.length));
            logger.info("> Registering new user: " + user[0] + " with the following Authorities[" + authoritiesStrings + "]");
            inMemoryUserDetailsManager.createUser(new User(user[0], passwordEncoder().encode(user[1]),
                    authoritiesStrings.stream().map(s -> new SimpleGrantedAuthority(s)).collect(Collectors.toList())));
        }


        return inMemoryUserDetailsManager;
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                .httpBasic();


    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

Start discovery table can be created out of, but it reported an error

Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'VERSION_' in 'field list'

View table, does not have this field, Issuses on Github, someone referred to this issue, the official reply to this version of this BUG, ​​the next version resolved, so do not use 7.1.0.M5 version of the activiti

Guess you like

Origin www.cnblogs.com/wuxiiiiiiii/p/12089903.html