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依赖。现在你可以编写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中添加数据库驱动依赖。现在添加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 集成相关推荐

  1. 企业级java b2bc商城系统开源源码二次开发(二十一)springboot集成JMS

    构架工程 创建一个springboot工程,在其pom文件加入: 1 2 3 4 <dependency> <groupId>org.springframework.boot& ...

  2. 《Flowable基础二 Flowable是什么》

    2.1. Flowable是什么? Flowable是一个使用Java编写的轻量级业务流程引擎.Flowable流程引擎让你可以部署BPMN 2.0流程定义(用于定义流程的行业XML标准).创建这些流 ...

  3. dubbo web工程示例_dubbo实战之二:与SpringBoot集成

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类和汇总,及配套源码,涉及Java.Docker.Kubernetes.DevO ...

  4. 【flowable】二、flowable入门

    flowable入门  在这个初步教程中,将构建一个简单的例子,以展示如何创建一个Flowable流程引擎,介绍一些核心概念,并展示如何使用API. 截图时使用的是Eclipse,但实际上可以使用任何 ...

  5. 企业级SpringBoot教程(十一)springboot集成swagger2,构建Restful API

    swagger,中文"拽"的意思.它是一个功能强大的api框架,它的集成非常简单,不仅提供了在线文档的查阅,而且还提供了在线文档的测试.另外swagger很容易构建restful风 ...

  6. SpringBoot 系列教程(四十一):SpringBoot集成RocketMQ(多模块方式)

    一.前言 RocketMQ是一款分布式.队列模型的消息中间件,是阿里巴巴集团自主研发的专业消息中间件,借鉴参考了JMS规范的MQ实现,更参考了优秀的开源消息中间件KAFKA,实现了业务消峰.分布式事务 ...

  7. SpringBoot第十二篇:springboot集成apidoc

    首先声明下,apidoc是基于注释来生成文档的,它不基于任何框架,而且支持大多数编程语言,为了springboot系列的完整性,所以标了个题. 一.apidoc简介 apidoc通过在你代码的注释来生 ...

  8. Bootstrap基础二十七 多媒体对象(Media Object)

    Bootstrap<基础二十七> 多媒体对象(Media Object) 原文:Bootstrap<基础二十七> 多媒体对象(Media Object) Bootstrap 中 ...

  9. Bootstrap基础二 网格系统

    原文:Bootstrap<基础二> 网格系统 Bootstrap 提供了一套响应式.移动设备优先的流式网格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列. 什 ...

最新文章

  1. 学了那么多年设计模式依然不会用!那可真蠢!
  2. Pro ASP.NET MVC –第五章 使用Razor
  3. LeetCode 38外观数列39组合总和
  4. NeurIPS 2020有哪些值得读的「图神经网络」论文?
  5. mysql8.0.15调优_Mysql 8.0 参数调优
  6. 【数据库】通用的存储过程
  7. 我的iOS学习历程 - UISegmentedControl
  8. autocad java api,autocad接口api
  9. vue-项目完成的项目报告
  10. arcgis使用工具箱导出dbf,怎么把excel表格导入gis!arcgis中属性表怎么导出到excel里...
  11. Linux系统如何安装oki打印机,涨知识!OKI针式打印机的驱动安装方法
  12. chardet.detect()
  13. 绪论--《可以量化的经济学》
  14. HTML figcaption 标签
  15. 带空格直角三角形图案
  16. 推荐好书《值得阅读的书籍》列表
  17. Java趣味编程案例12----孪生素数
  18. C++ 求100的阶乘
  19. LuaPlus学习(四)
  20. try-finally的详解

热门文章

  1. 线段树总结(一)【数据结构】
  2. 【BZOJ1146】【CTSC2008】网络管理 [整体二分]
  3. docker 1.8.2 源代码编译
  4. mysqldump 导出某几张表
  5. addslashes() 函数和PHP stripslashes() 函数
  6. linux线程同步(5)-屏障
  7. TCP close_wait 状态的解释
  8. new/delete和malloc/free的区别(举例说明)(简单点)
  9. ubuntu安装node.js
  10. 【机器学习入门笔记13:BP神经网络逼近股票收盘价格】20190218