當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringBoot集成flowable-modeler(6.4.1) 实现免登
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot集成flowable-modeler(6.4.1) 实现免登
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
因公司需求需要將flowable的流程設計器集成到項目中,下面將最近的研究成果記錄一下。
文章目錄
- 一、下載flowable-modeler源碼
- 二、添加相關maven包
- 三、調用idm服務重新接口
- 四、配置類
- 五、啟動類跳過登陸攔截
- 六、配置文件
一、下載flowable-modeler源碼
- 把flowable-ui-modeler-app\src\main\resources\static下面的代碼拷貝至我們自己的工程
二、添加相關maven包
<?xml version="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 http://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.0.7.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.gblfy</groupId><artifactId>flowable</artifactId><version>0.0.1-SNAPSHOT</version><name>flowable_modeler</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><!--去除本身的logback,使用log4j,如果想要使用logback需要添加commons-logging--><exclusions><!-- 去除舊log依賴 --><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><exclusions><!--去除本身的logback,使用log4j,如果想要使用logback需要添加commons-logging--><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId></exclusion></exclusions><scope>test</scope></dependency><!-- https://mvnrepository.com/artifact/commons-io/commons-io --><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.6</version></dependency><dependency><groupId>org.flowable</groupId><artifactId>flowable-groovy-script-static-engine</artifactId><version>6.4.1</version></dependency><dependency><groupId>org.codehaus.groovy</groupId><artifactId>groovy-all</artifactId><version>2.5.4</version><type>pom</type></dependency><!-- https://mvnrepository.com/artifact/commons-io/commons-io --><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.6</version></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.0.0</version></dependency><!-- https://mvnrepository.com/artifact/org.liquibase/liquibase-core --><dependency><groupId>org.liquibase</groupId><artifactId>liquibase-core</artifactId><version>3.6.2</version></dependency><!-- Logging --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>${slf4j.version}</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>${slf4j.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.springframework/spring-test --><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.0.9.RELEASE</version></dependency><!-- https://mvnrepository.com/artifact/org.flowable/flowable-spring-boot-starter-process --><dependency><groupId>org.flowable</groupId><artifactId>flowable-spring-boot-starter-process</artifactId><version>6.4.1</version></dependency><dependency><groupId>org.flowable</groupId><artifactId>flowable-ui-modeler-rest</artifactId><version>6.4.1</version></dependency><!-- dbpool的jar --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.12</version></dependency><!-- mysql驅動包 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.28</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>三、調用idm服務重新接口
- flowable獲取用戶是調用idm服務,這里前端修改獲取用戶信息接口自己實現接口
四、配置類
package com.gblfy.flowable.config;import liquibase.Liquibase; import liquibase.database.Database; import liquibase.database.DatabaseConnection; import liquibase.database.DatabaseFactory; import liquibase.database.jvm.JdbcConnection; import liquibase.exception.DatabaseException; import liquibase.resource.ClassLoaderResourceAccessor; import org.apache.ibatis.session.SqlSessionFactory; import org.flowable.common.engine.api.FlowableException; import org.flowable.spring.SpringProcessEngineConfiguration; import org.flowable.ui.common.service.exception.InternalServerErrorException; import org.mybatis.spring.SqlSessionFactoryBean; 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.core.io.ResourceLoader; import org.springframework.core.io.support.ResourcePatternUtils; import org.springframework.jdbc.datasource.DataSourceTransactionManager;import javax.sql.DataSource; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.Properties;/*** @ClassName ZhuangzProcessEngine* @Description TODO 構造流程引擎配置類* @Author gblfy* @Date 2019/11/17 20:12*/ @Configuration public class GblfyProcessEngine {private static final Logger LOGGER = LoggerFactory.getLogger(GblfyProcessEngine.class);//TODO 解決創建流程時報act_re_model找不到protected static final String LIQUIBASE_CHANGELOG_PREFIX = "ACT_DE_";@Autowiredprivate DataSource dataSource;@Autowiredprotected ResourceLoader resourceLoader;//事務管理器@Beanpublic DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource){DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(dataSource);return dataSourceTransactionManager;}@Beanpublic SpringProcessEngineConfiguration springProcessEngineConfiguration(){SpringProcessEngineConfiguration springProcessEngineConfiguration =new SpringProcessEngineConfiguration();springProcessEngineConfiguration.setDataSource(dataSource);springProcessEngineConfiguration.setDatabaseSchemaUpdate("true");springProcessEngineConfiguration.setTransactionManager(dataSourceTransactionManager(dataSource));return springProcessEngineConfiguration;}@Beanpublic SqlSessionFactory sqlSessionFactory(DataSource dataSource) {SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();sqlSessionFactoryBean.setDataSource(dataSource);String databaseType = initDatabaseType(dataSource);if (databaseType == null) {throw new FlowableException("couldn't deduct database type");}try {Properties properties = new Properties();properties.put("prefix", "");properties.put("blobType", "BLOB");properties.put("boolValue", "TRUE");properties.load(this.getClass().getClassLoader().getResourceAsStream("properties/" + databaseType + ".properties"));sqlSessionFactoryBean.setConfigurationProperties(properties);sqlSessionFactoryBean.setMapperLocations(ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath:/META-INF/modeler-mybatis-mappings/*.xml"));sqlSessionFactoryBean.afterPropertiesSet();return sqlSessionFactoryBean.getObject();} catch (Exception e) {throw new FlowableException("Could not create sqlSessionFactory", e);}}protected String initDatabaseType(DataSource dataSource) {String databaseType = null;Connection connection = null;try {connection = dataSource.getConnection();DatabaseMetaData databaseMetaData = connection.getMetaData();String databaseProductName = databaseMetaData.getDatabaseProductName();LOGGER.info("database product name: '{}'", databaseProductName);databaseType = databaseTypeMappings.getProperty(databaseProductName);if (databaseType == null) {throw new FlowableException("couldn't deduct database type from database product name '" + databaseProductName + "'");}LOGGER.info("using database type: {}", databaseType);} catch (SQLException e) {LOGGER.error("Exception while initializing Database connection", e);} finally {try {if (connection != null) {connection.close();}} catch (SQLException e) {LOGGER.error("Exception while closing the Database connection", e);}}return databaseType;}protected static Properties databaseTypeMappings = getDefaultDatabaseTypeMappings();public static final String DATABASE_TYPE_MYSQL = "mysql";public static final String DATABASE_TYPE_ORACLE = "oracle";public static Properties getDefaultDatabaseTypeMappings() {Properties databaseTypeMappings = new Properties();databaseTypeMappings.setProperty("MySQL", DATABASE_TYPE_MYSQL);databaseTypeMappings.setProperty("Oracle", DATABASE_TYPE_ORACLE);return databaseTypeMappings;}@Beanpublic Liquibase liquibase(DataSource dataSource) {LOGGER.info("Configuring Liquibase");Liquibase liquibase = null;try {DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);//TODO 解決創建流程時報act_re_model找不到database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());liquibase = new Liquibase("META-INF/liquibase/flowable-modeler-app-db-changelog.xml", new ClassLoaderResourceAccessor(), database);liquibase.update("flowable");return liquibase;} catch (Exception e) {throw new InternalServerErrorException("Error creating liquibase database", e);} finally {closeDatabase(liquibase);}}private void closeDatabase(Liquibase liquibase) {if (liquibase != null) {Database database = liquibase.getDatabase();if (database != null) {try {database.close();} catch (DatabaseException e) {LOGGER.warn("Error closing database", e);}}}} }五、啟動類跳過登陸攔截
package com.gblfy.flowable;import org.flowable.ui.modeler.properties.FlowableModelerAppProperties; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan;/*** SpringBoot啟動類** @Description跳過登陸攔截* @Author gblfy* @Date 2019/11/17 20:12*/ @SpringBootApplication(exclude = {SecurityAutoConfiguration.class}) @ComponentScan(basePackages = {"com.gblfy.flowable","org.flowable.ui.modeler","org.flowable.ui.common"}) public class FlowableApplication {public static void main(String[] args) {SpringApplication.run(FlowableApplication.class, args);}@Beanpublic FlowableModelerAppProperties flowableModelerAppProperties(){FlowableModelerAppProperties flowableModelerAppProperties = new FlowableModelerAppProperties();return flowableModelerAppProperties;} }六、配置文件
server:port: 80 spring:datasource:url: jdbc:mysql://localhost:3306/flowable_boot?zeroDateTimeBehavior=convertToNull&useUnicode=true&useSSL=false&rewriteBatchedStatements=truedriver-class-name: com.mysql.jdbc.Driverusername: rootpassword: roottype: com.alibaba.druid.pool.DruidDataSourceflowable:#關閉定時任務JOBasync-executor-activate: false將databaseSchemaUpdate設置為true。當Flowable發現庫與數據庫表結構不一致時,會自動將數據庫表結構升級至新版本。database-schema-update: truecommon:app:idm-url: http://127.0.0.1://80/flowable-idm項目源碼下載:
https://gitee.com/gb_90/flow-modeler-sduty
總結
以上是生活随笔為你收集整理的SpringBoot集成flowable-modeler(6.4.1) 实现免登的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Vue + Spring Boot 项目
- 下一篇: (需求实战_进阶_06)SSM集成Rab