1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Flowable6.5 之 springboot集成flowable modeler设计器

Flowable6.5 之 springboot集成flowable modeler设计器

时间:2020-12-05 19:22:14

相关推荐

Flowable6.5 之 springboot集成flowable modeler设计器

源码

githup上下载老版本源码/flowable/flowable-engine/releases

gitHub:/flowable/flowable-engine

flowable的sql文件则需要到官网下载:flowable官网

下载后解压,sql文件在 flowable-6.5.0\database\create\all中,根据需要导入即可,我使用的是mysql,即导入flowable.mysql.all.create.sql文件

flowable-6.5.0 源码目录

开始正题:直接在springboot集成flowable modeler设计器,比自带的更便利好用,使用的版本是springboot2.3.1,flowable6.5.0maven依赖

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.1.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>priv.gitonline</groupId><artifactId>flowable-ui</artifactId><version>1.0</version><name>flowable-ui</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><flowable.version>6.5.0</flowable.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- flowable 集成依赖 rest,logic,conf --><dependency><groupId>org.flowable</groupId><artifactId>flowable-ui-modeler-rest</artifactId><version>${flowable.version}</version></dependency><dependency><groupId>org.flowable</groupId><artifactId>flowable-ui-modeler-logic</artifactId><version>${flowable.version}</version></dependency><dependency><groupId>org.flowable</groupId><artifactId>flowable-ui-modeler-conf</artifactId><version>${flowable.version}</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency></dependencies>

需要的文件

1.复制源代码 modules\flowable-ui-modeler\flowable-ui-modeler-app\src\main\resources\static文件夹下的所有文件到springboot项目的resources文件夹下

2.复制AppDispatcherServletConfiguration到任意位置

/* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** /licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package priv.gitonline.flowable.ui.config;import org.flowable.ui.modeler.rest.app.EditorGroupsResource;import org.flowable.ui.modeler.rest.app.EditorUsersResource;import org.flowable.ui.modeler.rest.app.StencilSetResource;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;import org.springframework.context.annotation.Bean;import org.springframework.ponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.FilterType;import org.springframework.scheduling.annotation.EnableAsync;import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;import org.springframework.web.servlet.i18n.SessionLocaleResolver;import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;@Configuration@ComponentScan(value = { "org.flowable.ui.modeler.rest.app"// 不加载 rest,因为 getAccount 接口需要我们自己实现//,"org.mon.rest"},excludeFilters = {// 移除 EditorUsersResource 与 EditorGroupsResource,因为不使用 IDM 部分@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 = StencilSetResource.class),})@EnableAsyncpublic class AppDispatcherServletConfiguration implements WebMvcRegistrations {private static final Logger LOGGER = LoggerFactory.getLogger(AppDispatcherServletConfiguration.class);@Beanpublic SessionLocaleResolver localeResolver() {return new SessionLocaleResolver();}@Beanpublic LocaleChangeInterceptor localeChangeInterceptor() {LOGGER.debug("Configuring localeChangeInterceptor");LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();localeChangeInterceptor.setParamName("language");return localeChangeInterceptor;}@Overridepublic RequestMappingHandlerMapping getRequestMappingHandlerMapping() {LOGGER.debug("Creating requestMappingHandlerMapping");RequestMappingHandlerMapping requestMappingHandlerMapping = new RequestMappingHandlerMapping();requestMappingHandlerMapping.setUseSuffixPatternMatch(false);requestMappingHandlerMapping.setRemoveSemicolonContent(false);Object[] interceptors = { localeChangeInterceptor() };requestMappingHandlerMapping.setInterceptors(interceptors);return requestMappingHandlerMapping;}}

3.复制ApplicationConfiguration 到任意位置

/* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** /licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package priv.gitonline.flowable.ui.config;import org.mon.service.idm.RemoteIdmService;import org.flowable.ui.modeler.properties.FlowableModelerAppProperties;import org.flowable.ui.modeler.servlet.ApiDispatcherServletConfiguration;import org.springframework.boot.context.properties.EnableConfigurationProperties;import org.springframework.boot.web.servlet.ServletRegistrationBean;import org.springframework.context.ApplicationContext;import org.springframework.context.annotation.Bean;import org.springframework.ponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.FilterType;import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;import org.springframework.web.servlet.DispatcherServlet;@Configuration(proxyBeanMethods = false)@EnableConfigurationProperties(FlowableModelerAppProperties.class)@ComponentScan(basePackages = {// "org.flowable.ui.modeler.conf", //不引入 conf"org.flowable.ui.modeler.repository","org.flowable.ui.modeler.service",// "org.flowable.ui.modeler.security",//授权方面的都不需要// "org.mon.conf", // flowable 开发环境内置的数据库连接// "org.mon.filter",// IDM 方面的过滤器"org.mon.service","org.mon.repository",// "org.mon.security",//授权方面的都不需要"org.mon.tenant" },excludeFilters = {// 移除 RemoteIdmService@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = RemoteIdmService.class)})public class ApplicationConfiguration {@Beanpublic ServletRegistrationBean modelerApiServlet(ApplicationContext applicationContext) {AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();dispatcherServletConfiguration.setParent(applicationContext);dispatcherServletConfiguration.register(ApiDispatcherServletConfiguration.class);DispatcherServlet servlet = new DispatcherServlet(dispatcherServletConfiguration);ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, "/api/*");registrationBean.setName("Flowable Modeler App API Servlet");registrationBean.setLoadOnStartup(1);registrationBean.setAsyncSupported(true);return registrationBean;}}

4.复制FlowableStencilSetResource 到任意位置

/* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** /licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package priv.gitonline.flowable.ui.config;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import org.mon.service.exception.InternalServerErrorException;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping("/app")public class FlowableStencilSetResource {private static final Logger LOGGER = LoggerFactory.getLogger(FlowableStencilSetResource.class);@Autowiredprotected ObjectMapper objectMapper;@GetMapping(value = "/rest/stencil-sets/editor", produces = "application/json")public JsonNode getStencilSetForEditor() {try {JsonNode stencilNode = objectMapper.readTree(this.getClass().getClassLoader().getResourceAsStream("stencilset/stencilset_bpmn.json"));return stencilNode;} catch (Exception e) {LOGGER.error("Error reading bpmn stencil set json", e);throw new InternalServerErrorException("Error reading bpmn stencil set json");}}@GetMapping(value = "/rest/stencil-sets/cmmneditor", produces = "application/json")public JsonNode getCmmnStencilSetForEditor() {try {JsonNode stencilNode = objectMapper.readTree(this.getClass().getClassLoader().getResourceAsStream("stencilset/stencilset_cmmn.json"));return stencilNode;} catch (Exception e) {LOGGER.error("Error reading bpmn stencil set json", e);throw new InternalServerErrorException("Error reading bpmn stencil set json");}}}

5.复制FlowableController 到任意位置

package priv.gitonline.flowable.ui.config;import org.mon.model.UserRepresentation;import org.mon.security.DefaultPrivileges;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;import java.util.ArrayList;import java.util.List;@RestController@RequestMapping("/login")public class FlowableController {/*** 获取默认的管理员信息* @return*/@RequestMapping(value = "/rest/account", method = RequestMethod.GET, produces = "application/json")public UserRepresentation getAccount() {UserRepresentation userRepresentation = new UserRepresentation();userRepresentation.setId("admin");userRepresentation.setEmail("admin@");userRepresentation.setFullName("Administrator");// userRepresentation.setLastName("Administrator");userRepresentation.setFirstName("Administrator");List<String> privileges = new ArrayList<>();privileges.add(DefaultPrivileges.ACCESS_MODELER);privileges.add(DefaultPrivileges.ACCESS_IDM);privileges.add(DefaultPrivileges.ACCESS_ADMIN);privileges.add(DefaultPrivileges.ACCESS_TASK);privileges.add(DefaultPrivileges.ACCESS_REST_API);userRepresentation.setPrivileges(privileges);return userRepresentation;}}

6.新建包org.mon.security并复制SecurityUtils到包里

/* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** /licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.mon.security;import org.flowable.idm.api.User;import org.mon.model.RemoteUser;import org.mon.security.FlowableAppUser;import org.springframework.security.core.GrantedAuthority;import org.springframework.security.core.context.SecurityContext;import org.springframework.security.core.context.SecurityContextHolder;import java.util.ArrayList;import java.util.List;/*** Utility class for Spring Security.*/public class SecurityUtils {private static User assumeUser;private SecurityUtils() {}/*** Get the login of the current user.*/public static String getCurrentUserId() {User user = getCurrentUserObject();if (user != null) {return user.getId();}return null;}/*** @return the {@link User} object associated with the current logged in user.*/public static User getCurrentUserObject() {if (assumeUser != null) {return assumeUser;}// User user = null;// FlowableAppUser appUser = getCurrentFlowableAppUser();// if (appUser != null) {//user = appUser.getUserObject();// }//自定义用户RemoteUser user = new RemoteUser();user.setId("admin");user.setDisplayName("Administrator");user.setFirstName("Administrator");user.setLastName("Administrator");user.setEmail("admin@");user.setPassword("123456");List<String> pris = new ArrayList<>();pris.add(DefaultPrivileges.ACCESS_MODELER);pris.add(DefaultPrivileges.ACCESS_IDM);pris.add(DefaultPrivileges.ACCESS_ADMIN);pris.add(DefaultPrivileges.ACCESS_TASK);pris.add(DefaultPrivileges.ACCESS_REST_API);user.setPrivileges(pris);return user;}public static FlowableAppUser getCurrentFlowableAppUser() {FlowableAppUser user = null;SecurityContext securityContext = SecurityContextHolder.getContext();if (securityContext != null && securityContext.getAuthentication() != null) {Object principal = securityContext.getAuthentication().getPrincipal();if (principal instanceof FlowableAppUser) {user = (FlowableAppUser) principal;}}return user;}public static boolean currentUserHasCapability(String capability) {FlowableAppUser user = getCurrentFlowableAppUser();for (GrantedAuthority grantedAuthority : user.getAuthorities()) {if (capability.equals(grantedAuthority.getAuthority())) {return true;}}return false;}public static void assumeUser(User user) {assumeUser = user;}public static void clearAssumeUser() {assumeUser = null;}}

7.在springboot项目resources下建个文件夹stencilset,把下面链接里的两个文件下载下来拷贝进去

/gitonlie/flowable-ui/tree/master/src/main/resources/stencilset8.修改springboot项目resources\static\scripts\configuration\url-config.js

/* ACCOUNT URLS */getAccountUrl: function () {// return FLOWABLE.CONFIG.contextRoot + '/app/rest/account';return FLOWABLE.CONFIG.contextRoot + '/login/rest/account';},

application.yml配置

#mysqlspring.datasource.url=jdbc:mysql://localhost:3306/flowable_ui?useUnicode=true&characterEncoding=utf8&serverTimezone=UTCspring.datasource.username=rootspring.datasource.password=ADMIN123spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

异常1 :

com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value

解决:在datasource.url后改成:

jdbc:mysql://127.0.0.1:3306/flowable?characterEncoding=UTF-8&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

异常2 :原因为扫描不到flowable自有mapper.xml

Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.flowable.ui.modeler.domain.Model.selectModelByParameters

解决:在application.yml中增加mybatis配置

mybatis:mapper-locations: classpath:mapper/*.xml,mapper/*/*.xml,classpath*:mapper/*.xml,classpath:/META-INF/modeler-mybatis-mappings/*.xml#逗号前面的是本项目的mapper.xml位置,逗号后面的是楼主的报错,也就是没有找到(Mapped Statements collection does not contain value for org.flowable.ui.modeler.domain.Model.selectModelByParameters)configuration-properties:prefix:blobType: BLOBboolValue: TRUE

启动

启动后直接访问 localhost:8080 即可

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。