Spring 启动 webflux 无法解析 RestController

Spring boot webflux unable to resolve RestController

我最近才开始使用 Spring-boot starter webflux 来尝试响应式 Web 堆栈,我 运行 正在解决项目中一个非常简单的 RestController 的问题。

这里是拼图的必要部分:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.hello.sample</groupId>
    <artifactId>sample-reactive-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>sample-reactive-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

SampleController.java

package com.hello.sample.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController
{

    @GetMapping("/hello")
    public String hello()
    {
        return "Hello WebFlux";
    }
}

我在 application.properties

中设置了以下属性
server.port=8911
server.servlet.context-path=/sample-reactive

现在,当我 运行 应用程序作为 Spring 通过 Eclipse 启动应用程序并执行 curl 或 Postman 请求时,我得到一个 404 :

查看控制台日志,我没有看到任何请求映射绑定到已定义的请求映射。

这是控制台日志 . ____ _ __ _ _

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

2019-04-09 17:18:40.835  INFO 59587 --- [           main] i.n.d.s.SampleReactiveServiceApplication : Starting SampleReactiveServiceApplication on C02NJ38EG3QP-2.local with PID 59587 (/Users/developer/Documents/navajoWorkspace/sample-reactive-service/target/classes started by developer in /Users/developer/Documents/navajoWorkspace/sample-reactive-service)
2019-04-09 17:18:40.837  INFO 59587 --- [           main] i.n.d.s.SampleReactiveServiceApplication : No active profile set, falling back to default profiles: default
2019-04-09 17:18:41.631  INFO 59587 --- [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port(s): 8911
2019-04-09 17:18:41.634  INFO 59587 --- [           main] i.n.d.s.SampleReactiveServiceApplication : Started SampleReactiveServiceApplication in 0.972 seconds (JVM running for 1.527)

关于为什么会发生这种情况的任何想法,因为根据文档,我了解到即使使用 Webflux

也可以使用 @RestController 注释
Webflux 支持

context-pathhttps://github.com/spring-projects/spring-boot/issues/14082