1-Springboot集成FLOWABLE
flowable有驳回功能,单单就这点我感觉就比activiti强。1、新建maven子工程,其中pom内容如下这里我只列出与flowable有关的引用,我用的是6.5.0的版本<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:s
先展示集成效果:
后端
1、新建maven子工程,其中pom内容如下
这里我只列出与flowable有关的引用,我用的是6.5.0的版本
<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.jeecgframework.boot</groupId>
<artifactId>d-twins-parent</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>d-twins-workflow</artifactId>
<dependencies>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>6.5.0</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-rest</artifactId>
<version>6.5.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-conf</artifactId>
<version>6.5.0</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-rest</artifactId>
<version>6.5.0</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-task-conf</artifactId>
<version>6.5.0</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-admin-conf</artifactId>
<version>6.5.0</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-idm-conf</artifactId>
<version>6.5.0</version>
</dependency>
</dependencies>
</project>
2、设置配置类
package org.jeecg.workflow.core.configuartion;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.rest.service.api.RestResponseFactory;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.flowable.spring.boot.FlowableSecurityAutoConfiguration;
import org.flowable.ui.common.service.exception.InternalServerErrorException;
import org.flowable.ui.common.service.idm.RemoteIdmService;
import org.flowable.ui.modeler.properties.FlowableModelerAppProperties;
import org.flowable.ui.modeler.rest.app.EditorGroupsResource;
import org.flowable.ui.modeler.rest.app.EditorUsersResource;
import org.flowable.ui.modeler.rest.app.ModelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import com.fasterxml.jackson.databind.ObjectMapper;
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 lombok.extern.slf4j.Slf4j;
@Configuration
@EnableConfigurationProperties({ FlowableModelerAppProperties.class })
@ComponentScan(basePackages = { "org.flowable.ui.modeler.repository", "org.flowable.ui.modeler.service",
"org.flowable.ui.common.service", "org.flowable.ui.common.repository", "org.flowable.ui.common.tenant",
"org.flowable.ui.modeler.rest.app", "org.flowable.rest.service.api",
"org.flowable.ui.task.service.debugger" }, excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = RemoteIdmService.class),
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ModelResource.class),
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = EditorUsersResource.class),
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = EditorGroupsResource.class),
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = FlowableSecurityAutoConfiguration.class) })
@Slf4j
public class FlowableConfiguration implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {
@Value("${spring.datasource.dynamic.datasource.master.url}")
private String jdbcUrl;
@Value("${spring.datasource.dynamic.datasource.master.driver-class-name}")
private String jdbcDriverClassName;
@Value("${spring.datasource.dynamic.datasource.master.username}")
private String username;
@Value("${spring.datasource.dynamic.datasource.master.password}")
private String password;
@Override
public void configure(SpringProcessEngineConfiguration engineConfiguration) {
engineConfiguration.setJdbcUrl(jdbcUrl);
engineConfiguration.setJdbcDriver(jdbcDriverClassName);
engineConfiguration.setJdbcUsername(username);
engineConfiguration.setJdbcPassword(password);
}
@Autowired
protected ObjectMapper objectMapper;
@ConditionalOnMissingBean
@Bean
public RestResponseFactory restResponseFactory() {
return new RestResponseFactory(objectMapper);
}
@Bean
public Liquibase liquibase(DataSource dataSource) {
log.info("Configuring Liquibase");
Liquibase liquibase = null;
try {
DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
database.setDatabaseChangeLogTableName("ACT_DE_" + database.getDatabaseChangeLogTableName());
database.setDatabaseChangeLogLockTableName("ACT_DE_" + 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) {
log.warn("Error closing database", e);
}
}
}
}
}
flowable配置还是很自由的, 实现接口EngineConfigurationConfigurer,可以注入数据库连接参数。
3、FlowbleSecurityConfiguration 放开springsecurity限制。
package org.jeecg.workflow.core.configuartion;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.web.firewall.DefaultHttpFirewall;
import org.springframework.security.web.firewall.HttpFirewall;
@Configuration
@EnableWebSecurity
public class FlowbleSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests().antMatchers("/**").permitAll().anyRequest().authenticated().and()
.httpBasic();
}
@Bean
public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
return new DefaultHttpFirewall();
}
}
4、重写源类org.flowable.ui.modeler.rest.app.ModelResource
由上图可以看出ModelResource同时在这两个路径下,第二步我们虽然扫描了包路径org.flowable.ui.modeler.rest.app但是忽略了ModelResource这个类,(为什么会出现同名的component,我感觉这里真的是坑。。感觉是官方故意的) 但是这个类的功能在前端会请求这个类的功能,所以我们新建一个类,命名随意,把org.flowable.ui.modeler.rest.app.ModelResource的代码复制到新的类里面。比如我这里新建的类叫JeccgModelResource
到这里后端算是集成完了,有人或许会疑问是不是自己要写类似于完成任务,接受任务,发布模型啥功能,其实官网的rest在flowable-rest jar下,基本所有需要用
到的服务官方已经封装了,我们就不需要再自己写一遍了。而且swagger注释很全,这点我感觉flowable做的蛮好的
5、配置文件
其中mybatis plus 设置要改下,不然创建act_de_model表会有问题。
mybatis-plus:
mapper-locations: classpath*:org/jeecg/**/xml/*Mapper.xml, classpath:/META-INF/modeler-mybatis-mappings/*.xml
configuration-properties:
blobType: BLOB
boolValue: true
prefix: ''
最后表应该有83张
更多推荐
所有评论(0)