仅将spring-boot-starter-webflux添加为maven依赖项时,无法解析注释@RestController:

@RestController
public class MyController {

}

pom.xml:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.6</version>
    <relativePath/>
</parent>

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

这里少了什么?根据许多参考资料(如https://medium.com/javarevisited/basic-introduction-to-spring-webflux-eb155f501b17),webflux依赖项应该足以在spring boot中提供webflux webservice.

推荐答案

RestController注释是org的一部分.springframework:SpringWeb:依赖关系

enter image description here

org.springframework:spring-web依赖关系是org.springframework.boot:spring-boot-starter-webflux jar的一部分,所以应该得到解决.通过从终端运行mvn dependency:tree命令,可以判断完整的依赖关系层次 struct .

[INFO] +- org.springframework.boot:spring-boot-starter-webflux:jar:2.6.6:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.6.6:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.6.6:compile
[INFO] |  |  |  \- org.springframework:spring-context:jar:5.3.18:compile
[INFO] |  |  |     +- org.springframework:spring-aop:jar:5.3.18:compile
[INFO] |  |  |     \- org.springframework:spring-expression:jar:5.3.18:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.6.6:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.6.6:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.2.11:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.2:compile
[INFO] |  |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.36:compile
[INFO] |  |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.29:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.6.6:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.13.2.2:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.13.2:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.13.2:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.13.2:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.13.2:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.13.2:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:2.6.6:compile
[INFO] |  |  \- io.projectreactor.netty:reactor-netty-http:jar:1.0.17:compile
[INFO] |  |     +- io.netty:netty-codec-http:jar:4.1.75.Final:compile
[INFO] |  |     |  +- io.netty:netty-common:jar:4.1.75.Final:compile
[INFO] |  |     |  +- io.netty:netty-buffer:jar:4.1.75.Final:compile
[INFO] |  |     |  +- io.netty:netty-transport:jar:4.1.75.Final:compile
[INFO] |  |     |  +- io.netty:netty-codec:jar:4.1.75.Final:compile
[INFO] |  |     |  \- io.netty:netty-handler:jar:4.1.75.Final:compile
[INFO] |  |     +- io.netty:netty-codec-http2:jar:4.1.75.Final:compile
[INFO] |  |     +- io.netty:netty-resolver-dns:jar:4.1.75.Final:compile
[INFO] |  |     |  +- io.netty:netty-resolver:jar:4.1.75.Final:compile
[INFO] |  |     |  \- io.netty:netty-codec-dns:jar:4.1.75.Final:compile
[INFO] |  |     +- io.netty:netty-resolver-dns-native-macos:jar:osx-x86_64:4.1.75.Final:compile
[INFO] |  |     |  \- io.netty:netty-resolver-dns-classes-macos:jar:4.1.75.Final:compile
[INFO] |  |     +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.75.Final:compile
[INFO] |  |     |  +- io.netty:netty-transport-native-unix-common:jar:4.1.75.Final:compile
[INFO] |  |     |  \- io.netty:netty-transport-classes-epoll:jar:4.1.75.Final:compile
[INFO] |  |     \- io.projectreactor.netty:reactor-netty-core:jar:1.0.17:compile
[INFO] |  |        \- io.netty:netty-handler-proxy:jar:4.1.75.Final:compile
[INFO] |  |           \- io.netty:netty-codec-socks:jar:4.1.75.Final:compile
[INFO] |  +- org.springframework:spring-web:jar:5.3.18:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:5.3.18:compile
[INFO] |  \- org.springframework:spring-webflux:jar:5.3.18:compile

If you are starting a new project you can use the spring initializer - 100

Java相关问答推荐

ApachePOI:不带换行的新行

根据对象和值的参数将映射<;T、值&>转换为列表<;T&>

需要一个找不到的jakarta.sistence.EntityManager类型的Bean

使用Mockito进行的Junit测试失败

蒙蒂霍尔比赛结果不正确

在AVL树的Remove方法中使用NoSuchElementException时遇到问题

try 在Android Studio中的infoWindow中使用EditText(Java)

STREAMS减少部分结果的问题

JavaFX:无论何时显示应用程序,如何更改组件/ node 位置?

如何在IntelliJ IDEA的Build.sbt中添加外部JAR文件?

在Java中将.GRF转换为图像文件

Java中的发布/订阅-Long Live和Short Live Publisher,哪种方法是正确的?

当使用不同的参数类型调用时,为什么围绕Objects.equals的类型安全包装不会失败?

JOOQ:批处理CRUD操作使用动态表定义,如何?

当我将鼠标悬停在javafxTextArea上时,如何更改鼠标光标?

如何在 Android Studio 中删除 ImageView 和屏幕/父级边缘之间的额外空间?

我真的能很好地解释同步计数器和 AtomicInteger 的 JMH 结果吗

时间戳的日期时间字符串在 Select 时显示为本地时区而不是 UTC

Hibernate try 在 CrudRepository 中插入 null id

使用 dfs 迭代在有向图中查找循环的代码的时间和空间复杂度是多少