开发喵星球

若依项目分模块集成uflo2(203)

uflo2是一套由BSTEK自主研发的基于Java的工作流引擎,它以Spring为基础框架,采用Hibernate作为持久层,可运行于所有主流程应用服务器及流数据库之上的轻量级流程引擎。

本文主要介绍若依集成uflo2的流程

1. 新建子模块并导入依赖

1.1 新建子模块ruoyi-uflo

可参考【若依创建子模块详细教程(四)】

1.2 导入uflo2依赖

<description>
    uflo2流程管理模块
</description>

<dependencies>
    <!-- 通用工具-->
    <dependency>
        <groupId>com.ruoyi</groupId>
        <artifactId>ruoyi-common</artifactId>
    </dependency>

    <!-- uflo2依赖包-->
    <dependency>
        <groupId>com.bstek.uflo</groupId>
        <artifactId>uflo-console</artifactId>
        <version>2.1.4</version>
    </dependency>

</dependencies>

2. 添加config

2.1 添加ServletConfig.java

位置:ruoyi-uflo/src/main/java/com/ruoyi/ruoyiuflo/config/ServletConfig.java

package com.ruoyi.ruoyiuflo.config;

import com.bstek.uflo.console.UfloServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ServletConfig {
    @Bean
    public ServletRegistrationBean buildUfloServlet(){
        return new ServletRegistrationBean(new UfloServlet(),"/uflo/*");
    }
}

2.2 添加UfloConfig.java

位置:ruoyi-uflo/com/ruoyi/ruoyiuflo/config/UfloConfig.java

package com.ruoyi.ruoyiuflo.config;

import org.hibernate.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.util.Properties;

@Configuration
public class UfloConfig  {

    @Bean("localSessionFactoryBean")
    public LocalSessionFactoryBean localSessionFactoryBean(DataSource dataSource) throws
            PropertyVetoException, IOException {
        LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
        sessionFactoryBean.setDataSource(dataSource);
        sessionFactoryBean.setPackagesToScan("com.bstek.uflo.model*");
        Properties prop = new Properties();
        prop.put("hibernate.dialect","org.hibernate.dialect.MySQL5Dialect");
        prop.put("hibernate.show_sql",false);
        prop.put("hibernate.hbm2ddl.auto","update");
        prop.put("hibernate.jdbc.batch_size",100);
        sessionFactoryBean.setHibernateProperties(prop);

        return sessionFactoryBean;
    }

    @Bean("ufloTransactionManager")
    public HibernateTransactionManager ufloTransactionManager(SessionFactory sessionFactory){
        HibernateTransactionManager hi = new HibernateTransactionManager();
        hi.setSessionFactory(sessionFactory);
        return hi;
    }
}

2.3 添加 TestEnviromentProvider.java

位置:ruoyi-uflo/com/ruoyi/ruoyiuflo/env/TestEnviromentProvider.java

package com.ruoyi.ruoyiuflo.env;

import com.bstek.uflo.env.EnvironmentProvider;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;

import javax.annotation.Resource;

@Component
public class TestEnviromentProvider implements EnvironmentProvider {
    @Autowired
    private SessionFactory sessionFactory;

    @Resource(name = "ufloTransactionManager")
    private PlatformTransactionManager platformTransactionManager;

    @Override
    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public PlatformTransactionManager getPlatformTransactionManager() {
        return platformTransactionManager;
    }

    public void setPlatformTransactionManager(PlatformTransactionManager platformTransactionManager) {
        this.platformTransactionManager = platformTransactionManager;
    }

    @Override
    public String getLoginUser() {
        return null;
    }

    @Override
    public String getCategoryId() {
        return "anonymous";
    }

}

3. 导入uflo的配置文件

位置:ruoyi-admin模块的配置启动类RuoYiApplication.java

@ImportResource("classpath:uflo-console-context.xml")

4. 访问

项目启动成功后,会自动在数据库生成uflo相应的数据表

【待办任务】http://localhost:8088/uflo/todo

【流程设计】http://localhost:8088/uflo/designer

至此,访问代办任务和流程设计,若依集成uflo2已经完成。

   
分类:Java/OOP 作者:无限繁荣, 吴蓉 发表于:2024-05-10 09:07:28 阅读量:108
<<   >>


powered by kaifamiao