日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Flowable基础二十一 Flowable springboot 集成

發布時間:2025/3/21 78 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Flowable基础二十一 Flowable springboot 集成 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Spring Boot


????Spring Boot是一個應用框架,按照官網的介紹,可以輕松地創建獨立運行的,生產級別的,基于Spring的應用,并且可以“直接運行”。堅持使用Spring框架與第三方庫,使你可以輕松地開始使用。大多數Spring Boot應用只需要很少的Spring配置。

要獲得更多關于Spring Boot的信息,請查閱http://projects.spring.io/spring-boot/

????Flowable與Spring Boot的集成目前是我們與Spring的提交者共同開發的。

1.1. 兼容性 Compatibility

Spring Boot需要JDK 7運行時環境。可以通過調整配置,在JDK6下運行。請查閱Spring Boot的文檔。

1.2. 開始 Getting started

Spring Boot提倡約定大于配置。要開始工作,簡單地在你的項目中添加spring-boot-starters-basic依賴。例如在Maven中:

<dependency><groupId>org.flowable</groupId><artifactId>flowable-spring-boot-starter-basic</artifactId><version>${flowable.version}</version> </dependency>

就這么簡單。這個依賴會自動向classpath添加正確的Flowable與Spring依賴?,F在你可以編寫Spring Boot應用了:

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;@Configuration @ComponentScan @EnableAutoConfiguration public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);} }

Flowable需要數據庫存儲數據。如果你運行上面的代碼,會得到提示性的異常信息,指出需要在classpath中添加數據庫驅動依賴?,F在添加H2數據庫依賴:

<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><version>1.4.183</version> </dependency>

應用這次可以啟動了。你會看到類似這樣的輸出:

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.1.6.RELEASE) MyApplication : Starting MyApplication on ... s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@33cb5951: startup date [Wed Dec 17 15:24:34 CET 2014]; root of context hierarchy a.s.b.AbstractProcessEngineConfiguration : No process definitions were found using the specified path (classpath:/processes/**.bpmn20.xml). o.flowable.engine.impl.db.DbSqlSession : performing create on engine with resource org/flowable/db/create/flowable.h2.create.engine.sql o.flowable.engine.impl.db.DbSqlSession : performing create on history with resource org/flowable/db/create/flowable.h2.create.history.sql o.flowable.engine.impl.db.DbSqlSession : performing create on identity with resource org/flowable/db/create/flowable.h2.create.identity.sql o.a.engine.impl.ProcessEngineImpl : ProcessEngine default created o.a.e.i.a.DefaultAsyncJobExecutor : Starting up the default async job executor [org.flowable.spring.SpringAsyncExecutor]. o.a.e.i.a.AcquireTimerJobsRunnable : {} starting to acquire async jobs due o.a.e.i.a.AcquireAsyncJobsDueRunnable : {} starting to acquire async jobs due o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup MyApplication : Started MyApplication in 2.019 seconds (JVM running for 2.294)

只是在classpath中添加依賴,并使用@EnableAutoConfiguration注解,就會在幕后發生很多事情:

  • 自動創建了內存數據庫(因為classpath中有H2驅動),并傳遞給Flowable流程引擎配置

  • 創建并暴露了Flowable ProcessEngine bean

  • 所有的Flowable服務都暴露為Spring bean

  • 創建了Spring Job Executor

并且,processes目錄下的任何BPMN 2.0流程定義都會被自動部署。創建processes目錄,并在其中創建示例流程定義(命名為one-task-process.bpmn20.xml):

<?xml version="1.0" encoding="UTF-8"?><definitionsxmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"xmlns:flowable="http://flowable.org/bpmn"targetNamespace="Examples"><process id="oneTaskProcess" name="The One Task Process"><startEvent id="theStart" /><sequenceFlow id="flow1" sourceRef="theStart" targetRef="theTask" /><userTask id="theTask" name="my task" /><sequenceFlow id="flow2" sourceRef="theTask" targetRef="theEnd" /><endEvent id="theEnd" /></process> </definitions>

然后添加下列代碼,以測試部署是否生效。CommandLineRunner是一個特殊的Spring bean,在應用啟動時執行:

@Configuration @ComponentScan @EnableAutoConfiguration public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}@Beanpublic CommandLineRunner init(final RepositoryService repositoryService,final RuntimeService runtimeService,final TaskService taskService) {return new CommandLineRunner() {@Overridepublic void run(String... strings) throws Exception {System.out.println("Number of process definitions : "+ repositoryService.createProcessDefinitionQuery().count());System.out.println("Number of tasks : " + taskService.createTaskQuery().count());runtimeService.startProcessInstanceByKey("oneTaskProcess");System.out.println("Number of tasks after process start: "+ taskService.createTaskQuery().count());}};}}

會得到這樣的輸出:

Number of process definitions : 1 Number of tasks : 0 Number of tasks after process start : 1

總結

以上是生活随笔為你收集整理的Flowable基础二十一 Flowable springboot 集成的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。