基于WebFlux的响应式Spring初探demo

1、响应式编程式什么?为什么现在都认为这个是微服务的趋势?

先挖个坑吧,给个简单的公式。

响应式编程=数据流+变化传递+声明式

 

2、下面废话不多说直接上代码

WebFlux的核心Reactor的实现思路和介绍可跳转

https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-reactive-spring-web

因为是初探所以尽量给全代码,课详细了解引用的具体是什么类或者域,因为是自己简单实验,所以难免有错误,有同样也在研究的童靴如发现有错误请指教。

 

首先是项目启动类,与Spring Boot类似

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.reactive.config.EnableWebFlux;

@SpringBootApplication
@EnableWebFlux
public class WebfluxDemoApplication {

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

}

然后是我的针对web交互的一些配置。

主要是在Codec中增加了对LocalDateTime相关类和我自定义的两类枚举接口的序列化和反序列化的配置

package com.example.demo.config;

import static com.example.demo.utils.LocalDateTimeUtils.DATE_FORMATTER;
import static com.example.demo.utils.LocalDateTimeUtils.DATE_TIME_FORMATTER;
import static com.example.demo.utils.LocalDateTimeUtils.TIME_FORMATTER;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.codec.ServerCodecConfigurer;
imp
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值