我在我的 SpringBoot 应用程序中使用 Reactive 方法进行异步流处理。
我有这 6 个用于 SpringFramework 的导入
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import static org.springframework.web.reactive.function.server.RequestPredicates.*;
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
我在我的
pom.xml
中使用了这个依赖。 .但根据 Maven 中心,这些似乎最后一次使用是在 2016 年。<!-- https://mvnrepository.com/artifact/org.springframework/spring-web-reactive -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web-reactive</artifactId>
<version>5.0.0.M2</version>
</dependency>
这是我在 Maven 构建时的错误
[ERROR] Failed to execute goal on project SpringReactive: Could not resolve dependencies for project com.ayman:SpringReactive:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at org.springframework:spring-web-reactive:jar:5.0.0.M4: Failed to read artifact descriptor for org.springframework:spring-web-reactive:jar:5.0.0.M4: Could not transfer artifact org.springframework:spring-web-reactive:pom:5.0.0.M4 from/to public (https://globalrepositorymy-company'srepository.int/artifactory/public): connect timed out -> [Help 1]
这是因为我使用了已弃用的软件包,还是因为我损坏了软件包?
还是因为这些依赖项在我公司的存储库中不可用?
我剩下的
pom.xml
文件:-<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.ayman</groupId>
<artifactId>SpringReactive</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SpringReactive</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Reactor-Core -->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.1.8.RELEASE</version>
</dependency>
<!-- Spring-data-commons -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.0.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web-reactive -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web-reactive</artifactId>
<version>5.0.0.M4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-mongodb -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.0.8.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
最佳答案
spring-web-reactive
是模块的旧名称,在 Spring Framework 5.0 里程碑期间已更改。如您提到的链接所示,这些 Artifact 在 maven Central 上从未可用,而仅在 Spring Artifact 存储库上可用。
如果你看看the Spring Boot reference documentation ,你会看到 spring-boot-starter-webflux
是添加到您的应用程序以获取 spring-webflux
的依赖项,这是 Spring Framework 中响应式 Web 支持的模块名称。
请注意,因为您有 spring-boot-starter-web
已经在您的应用程序中,如果您添加 webflux 启动器,您的应用程序将仍然是 Spring MVC 应用程序,如 stated in the reference documentation .这没有什么问题,因为 Spring MVC 在某些情况下支持 Controller 签名中的 react 类型。这一切都归结为您要在这里实现的目标。
关于maven - 无法解析 spring-web-reactive 的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51166352/