Uflo2
是由 BSTEK
自主研发的一款基于 Java
的轻量级工作流引擎,采用 Spring
作为核心框架,并以 Hibernate
作为数据持久层,能够在大多数主流应用服务器和数据库上运行。本文将详细介绍如何在若依项目中集成 Uflo2
工作流引擎。
ruoyi-uflo
可以参照若依框架的创建子模块教程来新建子模块。
Uflo2
相关依赖在新建的 ruoyi-uflo
模块的 pom.xml
中,添加 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>
config
ServletConfig
在 ruoyi-uflo/src/main/java/com/ruoyi/ruoyiuflo/config/
路径下,创建 ServletConfig.java
文件,注册 UfloServlet
:
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<UfloServlet> registerUfloServlet() {
return new ServletRegistrationBean<>(new UfloServlet(), "/uflo/*");
}
}
UfloConfig
在同一目录下新增 UfloConfig.java
文件,配置 Hibernate
的 SessionFactory
及事务管理器:
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.io.IOException;
import java.util.Properties;
@Configuration
public class UfloConfig {
@Bean("localSessionFactoryBean")
public LocalSessionFactoryBean sessionFactory(DataSource dataSource) throws IOException {
LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource);
sessionFactoryBean.setPackagesToScan("com.bstek.uflo.model*");
Properties properties = new Properties();
properties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
properties.put("hibernate.show_sql", false);
properties.put("hibernate.hbm2ddl.auto", "update");
properties.put("hibernate.jdbc.batch_size", 100);
sessionFactoryBean.setHibernateProperties(properties);
return sessionFactoryBean;
}
@Bean("ufloTransactionManager")
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager transactionManager = new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory);
return transactionManager;
}
}
TestEnvironmentProvider
在 ruoyi-uflo/src/main/java/com/ruoyi/ruoyiuflo/env/
目录下创建 TestEnvironmentProvider.java
,实现 EnvironmentProvider
接口,用于配置工作流的环境:
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 TestEnvironmentProvider implements EnvironmentProvider {
@Autowired
private SessionFactory sessionFactory;
@Resource(name = "ufloTransactionManager")
private PlatformTransactionManager transactionManager;
@Override
public SessionFactory getSessionFactory() {
return sessionFactory;
}
@Override
public PlatformTransactionManager getPlatformTransactionManager() {
return transactionManager;
}
@Override
public String getLoginUser() {
return null;
}
@Override
public String getCategoryId() {
return "anonymous";
}
}
在若依主模块 ruoyi-admin
的启动类 RuoYiApplication.java
中,引入 uflo-console-context.xml
配置文件:
@ImportResource("classpath:uflo-console-context.xml")
当项目启动后,Uflo2
会自动在数据库中创建相关表
您可以通过以下链接访问 Uflo2
的管理页面:
【待办任务】
http://localhost:8088/uflo/todo
【流程设计】
http://localhost:8088/uflo/designer
通过以上步骤,Uflo2
已成功集成到若依项目中。
powered by kaifamiao