IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Java知识库 -> Spring WebFlux -> 正文阅读

[Java知识库]Spring WebFlux

传统的基于Servlet的Web框架,如Spring MVC,在本质上都是阻塞和多线程的,每个连接都会使用一个线程。在请求处理的时候,会在线程池中拉取一个工作者( worker )线程来对请求进行处理。同时,请求线程是阻塞的,直到工作者线程提示它已经完成为止。

首先webflux不是spring mvc的替代方案!webflux强调的是异步非阻塞,spring mvc强调的是同步阻塞,如果方案大部分偏向于非同步,则spring webflux才是首选。另外,如果依赖了大量阻塞式持久化 API 和网络 API,建议使? Spring MVC。

WebMVC:springMvc构建在servlet api之上,因此需要Servlet容器(比如Tomcat)才能执行。使用的是同步阻塞式IO模型,每一个请求对应一个线程去处理。

WebFlux:spring webflux是一个异步非阻塞式的web框架,它能够充分利用多核cpu的硬件资源去处理大量的并发请求。

相同之处

都可以使用springmvc注解,如@Controller,方便我们在两个web框架中自由转换;

都可以使用tomcat,jetty,undertow, servlet容器(servlet 3.1+)

注意点:

spring mvc因为是使用的同步阻塞式,更方便开发人员编写功能,debug测试等,一般来说,如果spring mvc能够满足的场景,就尽量不要用webflux;

使用WebFlux有一个很有 意思的副作用, 即WebFlux 的默认嵌人式服务器是Netty而不是Tomcat。Netty 是一个异步 、事件驱动的服务器,非常适合Spring WebFlux这样的反应式Web框架。

Spring WebFlux的控制器方法要接受和返回反应式类型,如Mono和Flux,而不是领域类型和集合。
?

SpringWebflux 实现方式有两种:注解编程模型函数式编程模型

基于注解编程模型

该模型与Spring MVC很相似。甚至注解都一样。

搭建一个简易的Spring WebFlux工程:

1,到https://start.spring.io/?创建spring boot工程,选择?Spring Reactive Web 依赖。

2,导入到IDEA,创建controller, service, entity 等包

3,创建entity

public class User {
    private int id;
    private String name;

    public User() {
    }

    public User(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

4,创建service 这里使用map模拟数据库操作

public interface UserService {

    Mono<User> selectById(int id);

    Flux<User> selectAllUsers();

    Mono<Void> insertUser(Mono<User> user);
}

@Repository
public class UserServiceImpl implements UserService {

    private static Map<Integer, User> users = new HashMap<>();

    public UserServiceImpl() {
        users.put(1, new User(1, "刘备"));
        users.put(2, new User(2, "曹操"));
        users.put(3, new User(3, "孙权"));
    }

    @Override
    public Mono<User> selectById(int id) {
        return Mono.just(users.get(id));
    }

    @Override
    public Flux<User> selectAllUsers() {
        return Flux.fromIterable(users.values());
    }

    @Override
    public Mono<Void> insertUser(Mono<User> userMono) {
        return userMono.doOnNext(user -> {
            int id = users.size() + 1;
            users.put(id, user);
        }).thenEmpty(Mono.empty());
    }
}

5,创建controller

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/users/{id}")
    public Mono<User> getUser(@PathVariable int id) {
        return userService.selectById(id);
    }

    @GetMapping("/users")
    public Flux<User> getAllUsers() {
        return userService.selectAllUsers();
    }

}

6,启动 SringBoot,这里修改了端口号为9999

"D:\Program Files\java\tsjdk64\bin\java.exe" -Dvisualvm.id=31217450973500 "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.2\lib\idea_rt.jar=64346:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.2\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\java\tsjdk64\jre\lib\charsets.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\access-bridge-64.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\cldrdata.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\dnsns.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\jaccess.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\localedata.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\nashorn.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\sunec.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\sunjce_provider.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\sunmscapi.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\sunpkcs11.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\zipfs.jar;D:\Program Files\java\tsjdk64\jre\lib\jce.jar;D:\Program Files\java\tsjdk64\jre\lib\jfr.jar;D:\Program Files\java\tsjdk64\jre\lib\jsse.jar;D:\Program Files\java\tsjdk64\jre\lib\management-agent.jar;D:\Program Files\java\tsjdk64\jre\lib\resources.jar;D:\Program Files\java\tsjdk64\jre\lib\rt.jar;D:\05_spring_dev\java-study\spring-webflux\target\classes;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-webflux\2.7.1\spring-boot-starter-webflux-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter\2.7.1\spring-boot-starter-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot\2.7.1\spring-boot-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-context\5.3.21\spring-context-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-aop\5.3.21\spring-aop-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-expression\5.3.21\spring-expression-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-autoconfigure\2.7.1\spring-boot-autoconfigure-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-logging\2.7.1\spring-boot-starter-logging-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\ch\qos\logback\logback-classic\1.2.11\logback-classic-1.2.11.jar;D:\Program Files\apache-maven-3.6.3\repo\ch\qos\logback\logback-core\1.2.11\logback-core-1.2.11.jar;D:\Program Files\apache-maven-3.6.3\repo\org\apache\logging\log4j\log4j-to-slf4j\2.17.2\log4j-to-slf4j-2.17.2.jar;D:\Program Files\apache-maven-3.6.3\repo\org\apache\logging\log4j\log4j-api\2.17.2\log4j-api-2.17.2.jar;D:\Program Files\apache-maven-3.6.3\repo\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;D:\Program Files\apache-maven-3.6.3\repo\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\Program Files\apache-maven-3.6.3\repo\org\yaml\snakeyaml\1.30\snakeyaml-1.30.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-json\2.7.1\spring-boot-starter-json-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\core\jackson-databind\2.13.3\jackson-databind-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\core\jackson-annotations\2.13.3\jackson-annotations-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\core\jackson-core\2.13.3\jackson-core-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.3\jackson-datatype-jdk8-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.3\jackson-datatype-jsr310-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.3\jackson-module-parameter-names-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-reactor-netty\2.7.1\spring-boot-starter-reactor-netty-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\io\projectreactor\netty\reactor-netty-http\1.0.20\reactor-netty-http-1.0.20.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-codec-http\4.1.78.Final\netty-codec-http-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-common\4.1.78.Final\netty-common-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-buffer\4.1.78.Final\netty-buffer-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-transport\4.1.78.Final\netty-transport-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-codec\4.1.78.Final\netty-codec-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-handler\4.1.78.Final\netty-handler-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-codec-http2\4.1.78.Final\netty-codec-http2-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-resolver-dns\4.1.78.Final\netty-resolver-dns-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-resolver\4.1.78.Final\netty-resolver-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-codec-dns\4.1.78.Final\netty-codec-dns-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-resolver-dns-native-macos\4.1.78.Final\netty-resolver-dns-native-macos-4.1.78.Final-osx-x86_64.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-resolver-dns-classes-macos\4.1.78.Final\netty-resolver-dns-classes-macos-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-transport-native-epoll\4.1.78.Final\netty-transport-native-epoll-4.1.78.Final-linux-x86_64.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-transport-native-unix-common\4.1.78.Final\netty-transport-native-unix-common-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-transport-classes-epoll\4.1.78.Final\netty-transport-classes-epoll-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\projectreactor\netty\reactor-netty-core\1.0.20\reactor-netty-core-1.0.20.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-handler-proxy\4.1.78.Final\netty-handler-proxy-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-codec-socks\4.1.78.Final\netty-codec-socks-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-web\5.3.21\spring-web-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-beans\5.3.21\spring-beans-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-webflux\5.3.21\spring-webflux-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-core\5.3.21\spring-core-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-jcl\5.3.21\spring-jcl-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\io\projectreactor\reactor-core\3.4.19\reactor-core-3.4.19.jar;D:\Program Files\apache-maven-3.6.3\repo\org\reactivestreams\reactive-streams\1.0.4\reactive-streams-1.0.4.jar" org.xharavard.webflux.WebfluxApplication

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.1)

2022-07-14 17:05:21.976  INFO 10060 --- [           main] o.xharavard.webflux.WebfluxApplication   : Starting WebfluxApplication using Java 1.8.0-taishan on LAPTOP-N89I5VOK with PID 10060 (D:\05_spring_dev\java-study\spring-webflux\target\classes started by xhh in D:\05_spring_dev\java-study)
2022-07-14 17:05:21.978  INFO 10060 --- [           main] o.xharavard.webflux.WebfluxApplication   : No active profile set, falling back to 1 default profile: "default"
2022-07-14 17:05:23.635  INFO 10060 --- [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port 9999
2022-07-14 17:05:23.640  INFO 10060 --- [           main] o.xharavard.webflux.WebfluxApplication   : Started WebfluxApplication in 2.045 seconds (JVM running for 2.394)

7,访问

浏览器输入:http://localhost:9999/users/1

返回? {"id":1,"name":"刘备"}


函数式编程模型

(1)在使用函数式编程模型操作时候,需要自己初始化服务器
(2)基于函数式编程模型时候,有两个核心接口:RouterFunction(实现路由功能,请求转发给对应的 handler)和 HandlerFunction(处理请求生成响应的函数)。核心任务定义两个函数式接口的实现并且启动需要的服务器。
(3)Spring WebFlux 请 求 和 响 应 不 再 是 ServletRequest 和 ServletResponse ,而是ServerRequest 和 ServerResponse
?

1,entity和service同之前一样

2,创建Handler

public class UserHandler {

    @Autowired
    private final UserService userService;

    public UserHandler(UserService userService) {
        this.userService = userService;
    }

    public Mono<ServerResponse> getUserById(ServerRequest request) {
        int userId = Integer.parseInt(request.pathVariable("id"));
        //空值处理
        Mono<ServerResponse> notFount = ServerResponse.notFound().build();
        Mono<User> userMono = this.userService.selectById(userId);
        return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(userMono, User.class)
            .switchIfEmpty(notFount);
    }

    public Mono<ServerResponse> getAllUsers(ServerRequest request) {
        Flux<User> users = this.userService.selectAllUsers();
        return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(users, User.class);
    }
}

3,初始化服务器,编写 Router

public class Server {

    public static void main(String[] args) throws IOException {
        Server server = new Server();
        server.createReactorServer();
        System.out.println("enter to exit");
        System.in.read();
    }

    // 创建路由
    public RouterFunction<ServerResponse> routingFunction() {
        UserService userService = new UserServiceImpl();
        UserHandler userHandler = new UserHandler(userService);

        return RouterFunctions
            .route(GET("/users/{id}").and(accept(MediaType.APPLICATION_JSON)), userHandler::getUserById)
            .andRoute(GET("/users").and(accept(MediaType.APPLICATION_JSON)), userHandler::getAllUsers);
    }

    // 创建服务器完成适配
    public void createReactorServer() {
        //路由和Handler适配
        RouterFunction<ServerResponse> route = routingFunction();
        HttpHandler httpHandler = toHttpHandler(route);
        ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);

        //创建服务器
        HttpServer httpServer = HttpServer.create();
        httpServer.handle(adapter).bindNow();

    }
}

启动上述程序

"D:\Program Files\java\tsjdk64\bin\java.exe" -Dvisualvm.id=32992872873300 "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.2\lib\idea_rt.jar=65106:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.2\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\java\tsjdk64\jre\lib\charsets.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\access-bridge-64.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\cldrdata.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\dnsns.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\jaccess.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\localedata.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\nashorn.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\sunec.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\sunjce_provider.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\sunmscapi.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\sunpkcs11.jar;D:\Program Files\java\tsjdk64\jre\lib\ext\zipfs.jar;D:\Program Files\java\tsjdk64\jre\lib\jce.jar;D:\Program Files\java\tsjdk64\jre\lib\jfr.jar;D:\Program Files\java\tsjdk64\jre\lib\jsse.jar;D:\Program Files\java\tsjdk64\jre\lib\management-agent.jar;D:\Program Files\java\tsjdk64\jre\lib\resources.jar;D:\Program Files\java\tsjdk64\jre\lib\rt.jar;D:\05_spring_dev\java-study\spring-webflux\target\classes;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-webflux\2.7.1\spring-boot-starter-webflux-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter\2.7.1\spring-boot-starter-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot\2.7.1\spring-boot-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-context\5.3.21\spring-context-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-aop\5.3.21\spring-aop-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-expression\5.3.21\spring-expression-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-autoconfigure\2.7.1\spring-boot-autoconfigure-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-logging\2.7.1\spring-boot-starter-logging-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\ch\qos\logback\logback-classic\1.2.11\logback-classic-1.2.11.jar;D:\Program Files\apache-maven-3.6.3\repo\ch\qos\logback\logback-core\1.2.11\logback-core-1.2.11.jar;D:\Program Files\apache-maven-3.6.3\repo\org\apache\logging\log4j\log4j-to-slf4j\2.17.2\log4j-to-slf4j-2.17.2.jar;D:\Program Files\apache-maven-3.6.3\repo\org\apache\logging\log4j\log4j-api\2.17.2\log4j-api-2.17.2.jar;D:\Program Files\apache-maven-3.6.3\repo\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;D:\Program Files\apache-maven-3.6.3\repo\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\Program Files\apache-maven-3.6.3\repo\org\yaml\snakeyaml\1.30\snakeyaml-1.30.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-json\2.7.1\spring-boot-starter-json-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\core\jackson-databind\2.13.3\jackson-databind-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\core\jackson-annotations\2.13.3\jackson-annotations-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\core\jackson-core\2.13.3\jackson-core-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.3\jackson-datatype-jdk8-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.3\jackson-datatype-jsr310-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.3\jackson-module-parameter-names-2.13.3.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-reactor-netty\2.7.1\spring-boot-starter-reactor-netty-2.7.1.jar;D:\Program Files\apache-maven-3.6.3\repo\io\projectreactor\netty\reactor-netty-http\1.0.20\reactor-netty-http-1.0.20.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-codec-http\4.1.78.Final\netty-codec-http-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-common\4.1.78.Final\netty-common-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-buffer\4.1.78.Final\netty-buffer-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-transport\4.1.78.Final\netty-transport-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-codec\4.1.78.Final\netty-codec-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-handler\4.1.78.Final\netty-handler-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-codec-http2\4.1.78.Final\netty-codec-http2-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-resolver-dns\4.1.78.Final\netty-resolver-dns-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-resolver\4.1.78.Final\netty-resolver-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-codec-dns\4.1.78.Final\netty-codec-dns-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-resolver-dns-native-macos\4.1.78.Final\netty-resolver-dns-native-macos-4.1.78.Final-osx-x86_64.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-resolver-dns-classes-macos\4.1.78.Final\netty-resolver-dns-classes-macos-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-transport-native-epoll\4.1.78.Final\netty-transport-native-epoll-4.1.78.Final-linux-x86_64.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-transport-native-unix-common\4.1.78.Final\netty-transport-native-unix-common-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-transport-classes-epoll\4.1.78.Final\netty-transport-classes-epoll-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\projectreactor\netty\reactor-netty-core\1.0.20\reactor-netty-core-1.0.20.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-handler-proxy\4.1.78.Final\netty-handler-proxy-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\io\netty\netty-codec-socks\4.1.78.Final\netty-codec-socks-4.1.78.Final.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-web\5.3.21\spring-web-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-beans\5.3.21\spring-beans-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-webflux\5.3.21\spring-webflux-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-core\5.3.21\spring-core-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\org\springframework\spring-jcl\5.3.21\spring-jcl-5.3.21.jar;D:\Program Files\apache-maven-3.6.3\repo\io\projectreactor\reactor-core\3.4.19\reactor-core-3.4.19.jar;D:\Program Files\apache-maven-3.6.3\repo\org\reactivestreams\reactive-streams\1.0.4\reactive-streams-1.0.4.jar" org.xharavard.webflux.Server
17:34:57.051 [main] DEBUG reactor.util.Loggers - Using Slf4j logging framework
17:34:57.299 [main] DEBUG org.springframework.web.server.adapter.HttpWebHandlerAdapter - enableLoggingRequestDetails='false': form data and headers will be masked to prevent unsafe logging of potentially sensitive data
17:34:57.331 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework
17:34:57.333 [main] DEBUG io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false
17:34:57.333 [main] DEBUG io.netty.util.internal.PlatformDependent0 - Java version: 8
17:34:57.334 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
17:34:57.334 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
17:34:57.334 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.storeFence: available
17:34:57.335 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
17:34:57.335 [main] DEBUG io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available
17:34:57.341 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
17:34:57.341 [main] DEBUG io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9
17:34:57.341 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available
17:34:57.341 [main] DEBUG io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available
17:34:57.342 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\xhh\AppData\Local\Temp (java.io.tmpdir)
17:34:57.342 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model)
17:34:57.342 [main] DEBUG io.netty.util.internal.PlatformDependent - Platform: Windows
17:34:57.343 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 3787980800 bytes
17:34:57.343 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1
17:34:57.344 [main] DEBUG io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available
17:34:57.344 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false
17:34:57.352 [main] DEBUG io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024
17:34:57.352 [main] DEBUG io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096
17:34:57.375 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple
17:34:57.375 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4
17:34:57.400 [main] DEBUG reactor.netty.tcp.TcpResources - [http] resources will use the default LoopResources: DefaultLoopResources {prefix=reactor-http, daemon=true, selectCount=8, workerCount=8}
17:34:57.400 [main] DEBUG reactor.netty.tcp.TcpResources - [http] resources will use the default ConnectionProvider: reactor.netty.resources.DefaultPooledConnectionProvider@65f095f8
17:34:57.401 [main] DEBUG reactor.netty.resources.DefaultLoopIOUring - Default io_uring support : false
17:34:57.654 [main] DEBUG reactor.netty.resources.DefaultLoopEpoll - Default Epoll support : false
17:34:57.655 [main] DEBUG reactor.netty.resources.DefaultLoopKQueue - Default KQueue support : false
17:34:57.660 [main] DEBUG io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 16
17:34:57.678 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false
17:34:57.678 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512
17:34:57.686 [main] DEBUG io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available
17:34:57.707 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.processId: 8008 (auto-detected)
17:34:57.709 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false
17:34:57.709 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false
17:34:57.851 [main] DEBUG io.netty.util.NetUtilInitializations - Loopback interface: lo (Software Loopback Interface 1, 127.0.0.1)
17:34:57.852 [main] DEBUG io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200
17:34:57.990 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.machineId: 8c:c6:81:ff:fe:4c:01:12 (auto-detected)
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 16
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 16
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 9
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 4194304
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimIntervalMillis: 0
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: false
17:34:58.005 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedByteBuffersPerChunk: 1023
17:34:58.010 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled
17:34:58.010 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0
17:34:58.010 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
17:34:58.077 [reactor-http-nio-1] DEBUG reactor.netty.transport.ServerTransport - [c9915a48, L:/0:0:0:0:0:0:0:0:65129] Bound new server
enter to exit
17:35:05.073 [reactor-http-nio-2] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true
17:35:05.074 [reactor-http-nio-2] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true
17:35:05.074 [reactor-http-nio-2] DEBUG io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@301be937
17:35:05.102 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServerOperations - [09cda6a3, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] New http connection, requesting read
17:35:05.102 [reactor-http-nio-3] DEBUG reactor.netty.http.server.HttpServerOperations - [1a0030eb, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65131] New http connection, requesting read
17:35:05.102 [reactor-http-nio-3] DEBUG reactor.netty.transport.TransportConfig - [1a0030eb, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65131] Initialized pipeline DefaultChannelPipeline{(reactor.left.httpCodec = io.netty.handler.codec.http.HttpServerCodec), (reactor.left.httpTrafficHandler = reactor.netty.http.server.HttpTrafficHandler), (reactor.right.reactiveBridge = reactor.netty.channel.ChannelOperationsHandler)}
17:35:05.102 [reactor-http-nio-2] DEBUG reactor.netty.transport.TransportConfig - [09cda6a3, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Initialized pipeline DefaultChannelPipeline{(reactor.left.httpCodec = io.netty.handler.codec.http.HttpServerCodec), (reactor.left.httpTrafficHandler = reactor.netty.http.server.HttpTrafficHandler), (reactor.right.reactiveBridge = reactor.netty.channel.ChannelOperationsHandler)}
17:35:05.106 [reactor-http-nio-2] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
17:35:05.106 [reactor-http-nio-2] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
17:35:05.106 [reactor-http-nio-2] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.chunkSize: 32
17:35:05.106 [reactor-http-nio-2] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.blocking: false
17:35:05.119 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServerOperations - [09cda6a3, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Increasing pending responses, now 1
17:35:05.124 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServer - [09cda6a3-1, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Handler is being applied: org.springframework.http.server.reactive.ReactorHttpHandlerAdapter@3bc10f7a
17:35:05.138 [reactor-http-nio-2] DEBUG org.springframework.web.server.adapter.HttpWebHandlerAdapter - [09cda6a3-1] HTTP GET "/users/1"
17:35:05.238 [reactor-http-nio-2] DEBUG org.springframework.http.codec.json.Jackson2JsonEncoder - [09cda6a3-1] Encoding [org.xharavard.webflux.entity.User@39412266]
17:35:05.252 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServerOperations - [09cda6a3-1, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Decreasing pending responses, now 0
17:35:05.252 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServerOperations - [09cda6a3-1, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Last HTTP packet was sent, terminating the channel
17:35:05.253 [reactor-http-nio-2] DEBUG org.springframework.web.server.adapter.HttpWebHandlerAdapter - [09cda6a3-1] Completed 200 OK
17:35:05.256 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServerOperations - [09cda6a3-1, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Last HTTP response frame
17:35:05.488 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServerOperations - [09cda6a3, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Increasing pending responses, now 1
17:35:05.488 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServer - [09cda6a3-2, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Handler is being applied: org.springframework.http.server.reactive.ReactorHttpHandlerAdapter@3bc10f7a
17:35:05.488 [reactor-http-nio-2] DEBUG org.springframework.web.server.adapter.HttpWebHandlerAdapter - [09cda6a3-2] HTTP GET "/favicon.ico"
17:35:05.494 [reactor-http-nio-2] DEBUG org.springframework.web.server.handler.ResponseStatusExceptionHandler - [09cda6a3-2] Resolved [ResponseStatusException: "404 NOT_FOUND "No matching router function""] for HTTP GET /favicon.ico
17:35:05.494 [reactor-http-nio-2] DEBUG org.springframework.web.server.adapter.HttpWebHandlerAdapter - [09cda6a3-2] Completed 404 NOT_FOUND
17:35:05.494 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServerOperations - [09cda6a3-2, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Last HTTP response frame
17:35:05.494 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServerOperations - [09cda6a3-2, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] No sendHeaders() called before complete, sending zero-length header
17:35:05.494 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServerOperations - [09cda6a3-2, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Decreasing pending responses, now 0
17:35:05.494 [reactor-http-nio-2] DEBUG reactor.netty.http.server.HttpServerOperations - [09cda6a3-2, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] Last HTTP packet was sent, terminating the channel
17:35:05.495 [reactor-http-nio-2] DEBUG reactor.netty.channel.ChannelOperationsHandler - [09cda6a3, L:/0:0:0:0:0:0:0:1:65129 - R:/0:0:0:0:0:0:0:1:65130] No ChannelOperation attached. Dropping: EmptyLastHttpContent

浏览器输入:http://localhost:65129/users

返回?[{"id":1,"name":"刘备"},{"id":2,"name":"曹操"},{"id":3,"name":"孙权"}]

  Java知识库 最新文章
计算距离春节还有多长时间
系统开发系列 之WebService(spring框架+ma
springBoot+Cache(自定义有效时间配置)
SpringBoot整合mybatis实现增删改查、分页查
spring教程
SpringBoot+Vue实现美食交流网站的设计与实
虚拟机内存结构以及虚拟机中销毁和新建对象
SpringMVC---原理
小李同学: Java如何按多个字段分组
打印票据--java
上一篇文章      下一篇文章      查看所有文章
加:2022-07-17 16:07:52  更:2022-07-17 16:08:53 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 15:24:47-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码