springboot集成flowable-modeler 实现免登

springboot集成flowable-modeler 实现免登

背景

因公司需求需要将flowable的流程设计器集成到项目中,下面将最近的研究成果记录一下。

步骤

这里用的是官网最新6.4.1(2019-3-14)

  1. 下载flowable-modeler源码,把flowable-ui-modeler-app\src\main\resources\static下面的代码拷贝至我们自己的工程。
    在这里插入图片描述

  2. 添加相关maven包

    <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-conf</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-ui-modeler-logic</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    
  3. 重写两个配置类

@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"},
        excludeFilters = {
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = RemoteIdmService.class)
})
public class ApplicationConfiguration {

    @Bean
    public ServletRegistrationBean apiServlet(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 IDM App API Servlet");
        registrationBean.setLoadOnStartup(1);
        registrationBean.setAsyncSupported(true);
        return registrationBean;
    }
}
@Configuration
@ComponentScan(value = {"org.flowable.ui.modeler.rest.app"},
        excludeFilters = {
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = EditorUsersResource.class),
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = EditorGroupsResource.class),
        })
@EnableAsync
public class AppDispatcherServletConfiguration implements WebMvcRegistrations {
    private static final Logger LOGGER = LoggerFactory.getLogger(AppDispatcherServletConfiguration.class);

    @Bean
    public SessionLocaleResolver localeResolver() {
        return new SessionLocaleResolver();
    }

    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LOGGER.debug("Configuring localeChangeInterceptor");
        LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
        localeChangeInterceptor.setParamName("language");
        return localeChangeInterceptor;
    }

    @Override
    public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
        LOGGER.debug("Creating requestMappingHandlerMapping");
        RequestMappingHandlerMapping requestMappingHandlerMapping = new RequestMappingHandlerMapping();
        requestMappingHandlerMapping.setUseSuffixPatternMatch(false);
        requestMappingHandlerMapping.setRemoveSemicolonContent(false);
        Object[] interceptors = { localeChangeInterceptor() };
        requestMappingHandlerMapping.setInterceptors(interceptors);
        return requestMappingHandlerMapping;
    }
}
  1. Springboot启动类Import两个配置类,并排除springsecurity认证
@Import({
        ApplicationConfiguration.class,
        AppDispatcherServletConfiguration.class
})
@SpringBootApplication(
        exclude = {SecurityAutoConfiguration.class})
public class FlowableDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(FlowableDemoApplication.class, args);
    }

}
  1. flowable获取用户是调用idm服务,这里前端修改获取用户信息接口自己实现接口
    在这里插入图片描述
@RestController
@RequestMapping("/demo")
public class DemoController {

    @RequestMapping(value = "/rest/account", method = RequestMethod.GET, produces = "application/json")
    public UserRepresentation getAccount() {
        UserRepresentation userRepresentation = new UserRepresentation();
        userRepresentation.setId("admin");
        userRepresentation.setEmail("admin@flowable.org");
        userRepresentation.setFullName("Test Administrator");
        userRepresentation.setLastName("Administrator");
        userRepresentation.setFirstName("Test");
        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;
    }
}
  1. 添加流程时会用到用户id,这里重构SecurityUtils.getCurrentUserObject 获取用户信息
public static User getCurrentUserObject() {
        if (assumeUser != null) {
            return assumeUser;
        }

        RemoteUser user = new RemoteUser();
        user.setId("admin");
        user.setDisplayName("admin");
        user.setFirstName("admin");
        user.setLastName("admin");
        user.setEmail("admin@admin.com");
        user.setPassword("test");
        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;
    }
  1. 指定 flowable的mapper文件的classpath路径
mybatis:
  mapper-locations: classpath:/META-INF/modeler-mybatis-mappings/*.xml

效果图

在这里插入图片描述
在这里插入图片描述

代码地址

代码下载(BPMN组件已汉化)

  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 31
    评论
要在Spring Boot中集成Flowable Modeler,可以按照以下步骤进行操作: 1. 添加依赖项 在pom.xml文件中添加以下依赖项: ``` <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter-modeler</artifactId> <version>${flowable.version}</version> </dependency> ``` 其中,${flowable.version}是Flowable版本号。 2. 配置数据库 在application.properties文件中,配置Flowable与Spring Boot共享的数据源,例如: ``` spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.jdbc.Driver #flowable配置 spring.datasource.flowable.driver-class-name=${spring.datasource.driver-class-name} spring.datasource.flowable.url=${spring.datasource.url} spring.datasource.flowable.username=${spring.datasource.username} spring.datasource.flowable.password=${spring.datasource.password} spring.datasource.flowable.maxActive=20 spring.datasource.flowable.maxIdle=10 spring.datasource.flowable.minIdle=5 spring.datasource.flowable.initialSize=5 spring.datasource.flowable.removeAbandoned=true spring.datasource.flowable.removeAbandonedTimeout=1800 spring.datasource.flowable.testOnBorrow=true spring.datasource.flowable.validationQuery=SELECT 1 ``` 3. 配置Flowable Modeler 在application.properties文件中,配置Flowable Modeler。以下是一个简单的示例: ``` #flowable modeler配置 spring.flowable.modeler.app.name=MyFlowableModeler spring.flowable.modeler.app.description=My Flowable Modeler spring.flowable.modeler.app.rest.root=http://localhost:8080/flowable-modeler spring.flowable.modeler.app.rest.account=admin spring.flowable.modeler.app.rest.password=admin ``` 4. 运行应用程序 现在,您可以运行Spring Boot应用程序,并在浏览器中访问Flowable Modeler,例如http://localhost:8080/modeler/index.html。使用上面的配置,您应该可以使用用户名“admin”和密码“admin”登录。 至此,您已经成功地将Flowable Modeler集成到Spring Boot应用程序中!
评论 31
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值