javascript
Spring boot 集成工作流flowable去掉xml配置
工作流Flowable和Spring集成時,有一個xml是用來配置ProcessEngine的信息,xml的內容如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsdhttp://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"><!-- Activiti begin --><bean id="processEngineConfiguration" class="com.xxx.xxx.config.ExtProcessEngineConfiguration"><property name="dataSource" ref="dataSource" /><property name="transactionManager" ref="transactionManager" /><property name="databaseSchemaUpdate" value="true" /><!-- property name="jobExecutorActivate" value="false" /--><property name="customSessionFactories"><list><bean class="com.xxx.xxx.entity.EntityManagerFactory"><constructor-arg index="0" value="org.flowable.idm.engine.impl.persistence.entity.UserEntityManager" /><constructor-arg index="1"><bean class="com.xxx.xxx.entity.SmartUserEntityManager"/></constructor-arg></bean><bean class="com.xxx.xxx.entity.EntityManagerFactory"><constructor-arg index="0" value="org.flowable.idm.engine.impl.persistence.entity.GroupEntityManager" /><constructor-arg index="1"><bean class="com.xxx.xxx.entity.SmartGroupEntityManager"/></constructor-arg></bean><bean class="com.xxx.xxx.entity.EntityManagerFactory"><constructor-arg index="0" value="org.flowable.idm.engine.impl.persistence.entity.MembershipEntityManager" /><constructor-arg index="1"><bean class="com.xxx.xxx.entity.SmartMembershipEntityManager"/></constructor-arg></bean></list></property></bean><bean id="processEngine" factory-bean="processEngineConfiguration" factory-method="buildProcessEngine" /><bean id="repositoryService" factory-bean="processEngineConfiguration" factory-method="getRepositoryService" /><bean id="runtimeService" factory-bean="processEngineConfiguration" factory-method="getRuntimeService" /><bean id="taskService" factory-bean="processEngineConfiguration" factory-method="getTaskService" /><bean id="historyService" factory-bean="processEngineConfiguration" factory-method="getHistoryService" /><bean id="managementService" factory-bean="processEngineConfiguration" factory-method="getManagementService" /><bean id="formService" factory-bean="processEngineConfiguration" factory-method="getFormService" /><bean id="identityService" factory-bean="processEngineConfiguration" factory-method="getIdentityService" /><bean id="commandExecutor" factory-bean="processEngineConfiguration" factory-method="getCommandExecutor" /><bean id="processDefinitionCache" factory-bean="processEngineConfiguration" factory-method="getProcessDefinitionCache"/></beans>使用Spring boot之后推崇java配置取代xml配置,要對這個xml進行改造首先得搞清楚這個xml里面的內容,主要是定義了ExtProcessEngineConfiguration和它相關的屬性,
說明:?
constructor-arg:通過構造函數注入。?
property:通過setter對應的方法注入。?
factory-method:通過工廠方法來構造java Bean
創建config配置文件WorkflowConfiguration,在這個類中通過@bean的注解構造ExtProcessEngineConfiguration 類,同時設置ExtProcessEngineConfiguration 需要的幾個屬性
其中核心的代碼是:
@Beanpublic ExtProcessEngineConfiguration engineConfiguration()這個方法。
其中有一個重點需要注意的地方是,在xml里面有一段:
<bean id="processEngine" factory-bean="processEngineConfiguration" factory-method="buildProcessEngine" />這個是Spring使用實例工廠方法實例化Bean的一種方式,工作作流引擎Flowable的各個組件就是使用此方式實例化的。由于使用工廠實例化的Bean跟普通Bean不同,其返回的對象不是指定類的一個實例,其返回的是該FactoryBean的getObject方法所返回的對象。因此我們需要使用Spring Boot的方式來實例化Flowable的組件。有兩種解決方法:
ProcessEngineFactoryBean最終返回的是processEngine對象,repositoryService、runtimeService、formService等等組件都是通過processEngine里的getXX方法獲得的。
通過WorkflowConfiguration就可以取代xml配置文件了。
在我們需要繼承flowable-restApi的時候發現需要進行權限校驗,我們可以通過下面的注解去掉security權限校驗,在啟動類上加上下面的注解:
@SpringBootApplication(exclude = {org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class,org.flowable.spring.boot.SecurityAutoConfiguration.class})?
總結
以上是生活随笔為你收集整理的Spring boot 集成工作流flowable去掉xml配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: feign调用session丢失解决方案
- 下一篇: Eclipse远程调试