package geektime.spring.springbucks;

import geektime.spring.springbucks.model.Coffee;
import geektime.spring.springbucks.model.CoffeeOrder;
import geektime.spring.springbucks.model.OrderState;
import geektime.spring.springbucks.service.CoffeeService;
import geektime.spring.springbucks.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component; import java.util.Arrays;
import java.util.Date; @Component
@Slf4j
public class SpringbucksRunner implements ApplicationRunner {
@Autowired
private CoffeeService coffeeService;
@Autowired
private OrderService orderService; @Override
public void run(ApplicationArguments args) throws Exception {
coffeeService.initCache()
.then(
coffeeService.findOneCoffee("mocha")
.flatMap(c -> {
CoffeeOrder order = createOrder("Li Lei", c);
return orderService.create(order);
})
.doOnError(t -> log.error("error", t)))
.subscribe(o -> log.info("Create Order: {}", o));
log.info("After Subscribe");
Thread.sleep(5000);
} private CoffeeOrder createOrder(String customer, Coffee... coffee) {
return CoffeeOrder.builder()
.customer(customer)
.items(Arrays.asList(coffee))
.state(OrderState.INIT)
.createTime(new Date())
.updateTime(new Date())
.build();
}
}

本文由博客群发一文多发等运营工具平台 OpenWrite 发布

java 与 springboot的更多相关文章

  1. Java结合SpringBoot拦截器实现简单的登录认证模块

    Java结合SpringBoot拦截器实现简单的登录认证模块 之前在做项目时需要实现一个简单的登录认证的功能,就寻思着使用Spring Boot的拦截器来实现,在此记录一下我的整个实现过程,源码见文章 ...

  2. Java逆向工程SpringBoot + Mybatis Generator + MySQL

    Java逆向工程SpringBoot+ Mybatis Generator + MySQL Meven pop.xml文件添加引用: <dependency> <groupId> ...

  3. JAVA - 创建SpringBoot项目

    JAVA - 创建SpringBoot项目 Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配 ...

  4. Java之SpringBoot自定义配置与整合Druid

    Java之SpringBoot自定义配置与整合Druid SpringBoot配置文件 优先级 前面SpringBoot基础有提到,关于SpringBoot配置文件可以是properties或者是ya ...

  5. Java发送邮件 —— SpringBoot集成Java Mail

    用途:此文仅供,自己今后的小程序通过邮件,批量通知用户. 简单记录了一些发送基本邮件的操作. 项目(SpringBoot版本为2.1.2.RELEASE): 核心依赖(其他相关依赖,在其使用的地方具体 ...

  6. 【Java】SpringBoot入门学习及基本使用

    SpringBoot入门及基本使用 SpringBoot的介绍我就不多说了,核心的就是"约定大于配置",接下来直接上干货吧! 本文的实例: github-LPCloud,欢迎sta ...

  7. 转 Java jar (SpringBoot Jar)转为win可执行的exe程序

    原文链接:http://voidm.com/2018/12/29/java-jar-transform-exe/打包Jar工程 将java项目打包成jar工程,可以是文章以SpringBoot为例po ...

  8. vs code 搭建java maven springboot环境

    Java Extension Pack,Maven for Java,Spring Boot Extension Pack https://blog.csdn.net/qq_26026975/arti ...

  9. 把java(springboot)程序打包docker镜像

    前言:要在docker运行java(jar包)程序,就要把程序打包成docker镜像(以下简称镜像),可以先理解为镜像就是jar包 打包需要程序代码,java本身的打包环境(包括jdk和maven), ...

  10. java事务/springboot事务/redis事务

    java事务(数据库事务):jdbc事务--ACID springboot事务:@Transactional--ACID redis事务:命令集合 将redis事务与mysql事务对比:   Mysq ...

随机推荐

  1. vue :关于引用jquery的二三问题

    webpack版本:3.6.0 首先是引用jquery. 有两个地方要改. 1 (项目地址)/build/webpack.base.conf.js 2 (项目地址)/src/main.js webpa ...

  2. 终于搞懂Spring中Scope为Request和Session的Bean了

    之前只是很模糊的知道其意思,在request scope中,每个request创建一个新的bean,在session scope中,同一session中的bean都是一样的 但是不知道怎么用代码去验证 ...

  3. 设计模式:Adapter模式

    目的:复用代码和兼容以前的代码 思想:提供一个中间层,做兼容 方法:“继承”的方式,“委托”的方式 继承关系图: 委托方式 继承方式 例子: //原来的打印 class Print { public: ...

  4. Asp.NetCore3.1 WebApi 使用Jwt 授权认证使用

    1:导入NuGet包 Microsoft.AspNetCore.Authentication.JwtBearer 2:配置 jwt相关信息 3:在 startUp中 public void Confi ...

  5. python 99乘法表

    先把代码贴上 for i in range(1,10): for j in range(1,i+1): s="%d X %d = %d"%(j,i,i*j) print(s,end ...

  6. 「从零单排canal 06」 instance模块源码解析

    基于1.1.5-alpha版本,具体源码笔记可以参考我的github:https://github.com/saigu/JavaKnowledgeGraph/tree/master/code_read ...

  7. 将形如 5D, 30s 的字符串转为秒

    import sys def convert_to_seconds(time_str): # write code here if 's' in time_str: return float(time ...

  8. PHP next() 函数

    实例 输出数组中的当前元素和下一个元素的值: <?php$people = array("Peter", "Joe", "Glenn" ...

  9. Android JNI之动态注册

    所谓动态注册,就是不用像静态注册那样按规则严格的命名native方法,而是在加载so库的时候完成这个从Java方法到native方法的匹配工作,而这个匹配工作,需要我们写native代码来完成.下面直 ...

  10. JS&ES6学习笔记(持续更新)

    ES6学习笔记(2019.7.29) 目录 ES6学习笔记(2019.7.29) let和const let let 基本用法 let 不存在变量提升 暂时性死区 不允许重复声明 块级作用域 级作用域 ...