明霞山资源网 Design By www.htccd.com

Activiti7发布正式版之后,它与SpringBoot2.x已经完全支持整合开发。我们可以将Activiti7与SpringBoot整合开发的坐标引入到工程中,从而达到SpringBoot支持Activti7整合。

1.使用IDEA创建SpringBoot项目

在工程的pom.xml文件中引入相关的依赖,具体依赖如下所示

<"1.0" encoding="UTF-8"?>
<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.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.example</groupId>
  <artifactId>activiti</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>activiti</name>
  <description>Demo project for Spring Boot</description>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>

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

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

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

    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-spring-boot-starter</artifactId>
      <version>7.0.0.Beta2</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.5</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.27</version>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <optional>true</optional>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

</project>

2.application.yml文件配置

为了能够实现Activiti7生成的表放到Mysql数据库中,需要在配置文件application.yml中添加相关的配置

server:
 port: 8085
spring:
 application:
  name: spring-activiti
 datasource:
  url: jdbc:mysql://localhost:3306/activiti"color: #ff0000">3.添加SpringSecurity安全框架整合配置

Activiti7与SpringBoot整合后,默认情况下,集成了SpringSecurity安全框架,这样我们就要去准备SpringSecurity整合进来的相关用户权限配置信息

1)添加SecurityUtil类

为了能够快速实现SpringSecurity安全框架的配置,所添加的一个组件。

@Component
public class SecurityUtil {

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

  @Autowired
  @Qualifier("myUserDetailsService")
  private UserDetailsService userDetailsService;

  public void logInAs(String username) {

    UserDetails user = userDetailsService.loadUserByUsername(username);
    if (user == null) {
      throw new IllegalStateException("User " + username + " doesn't exist, please provide a valid user");
    }
    logger.info("> Logged in as: " + username);
    SecurityContextHolder.setContext(new SecurityContextImpl(new Authentication() {
      @Override
      public Collection<"htmlcode">
@Configuration
public class DemoApplicationConfiguration {

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

  @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"},
        {"system", "password", "ROLE_ACTIVITI_USER"},
        {"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;
  }


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

}

4)创建测试类

@SpringBootTest
@Slf4j
class ActivitiApplicationTests {

  @Autowired
  private ProcessEngine processEngine;

  /**
   * 流程定义的部署
   */
  @Test
  public void createDeploy() { 
    RepositoryService repositoryService = processEngine.getRepositoryService();

    Deployment deployment = repositoryService.createDeployment()
        .addClasspathResource("diagram/holiday.bpmn")//添加bpmn资源
        .addClasspathResource("diagram/holiday.png")
        .name("请假申请单流程")
        .deploy(); 
        
    log.info("流程部署id:" + deployment.getName());
    log.info("流程部署名称:" + deployment.getId());
  }
}

运行结果:

SpringBoot整合Activiti7的实现代码

SpringBoot整合Activiti7的实现代码

遇到的问题:

1)历史表默认不会生成,需在application.yml中配置

spring:
 activiti:
  #检测历史表是否存在
  db-history-used: true
  #记录历史等级 可配置的历史级别有none, activity, audit, full
  history-level: full

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
SpringBoot整合Activiti7,SpringBoot,Activiti7

明霞山资源网 Design By www.htccd.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
明霞山资源网 Design By www.htccd.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。