gpt4 book ai didi

带有 REST 服务的 Spring Reactor

转载 作者:行者123 更新时间:2023-12-01 12:46:26 24 4
gpt4 key购买 nike

我正在尝试使用 Rest Service 实现 Spring Reactor。 Controller

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import reactor.core.publisher.Flux;


@RestController
public class CustomerController {


@Autowired
private FluxService fluxService;

@SuppressWarnings("unchecked")
@RequestMapping(path = "/handleMessageReactor", method = RequestMethod.POST)
public Flux<MessageAcknowledgement> handleMessage(@RequestBody Customer message) {
return fluxService.fluxMethod(message);
}
}

服务类

package com.nbcu;

import org.springframework.stereotype.Service;

import reactor.core.publisher.Flux;
@Service
public class FluxService {

MessageAcknowledgement msg;
public Flux fluxMethod(Customer cust)
{

System.out.println("Name"+cust.getName());
System.out.println("Address"+cust.getAddress());
msg=new MessageAcknowledgement("Success");
return Flux.just(msg);

}
}

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.nbcu</groupId>
<artifactId>Report</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>SpringReactor</name>
<description>Spring Reactor POC</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.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-jersey</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-web-services</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-bus</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectreactor/reactor-spring -->
<dependency>
<groupId>org.projectreactor</groupId>
<artifactId>reactor-spring</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>


<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-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>

这是下面的编译错误:

INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringReactor 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ Report ---
[INFO] Deleting D:\Workspace\SpringReactor\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Report ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Report ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to D:\Workspace\SpringReactor\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/Workspace/SpringReactor/src/main/java/com/nbcu/FluxService.java:[5,30] package reactor.core.publisher does not exist
[ERROR] /D:/Workspace/SpringReactor/src/main/java/com/nbcu/FluxService.java:[10,16] cannot find symbol
symbol: class Flux
location: class com.nbcu.FluxService
[ERROR] /D:/Workspace/SpringReactor/src/main/java/com/nbcu/CustomerController.java:[9,30] package reactor.core.publisher does not exist
[ERROR] /D:/Workspace/SpringReactor/src/main/java/com/nbcu/CustomerController.java:[21,12] cannot find symbol
symbol: class Flux
location: class com.nbcu.CustomerController
[ERROR] /D:/Workspace/SpringReactor/src/main/java/com/nbcu/FluxService.java:[16,24] cannot find symbol
symbol: variable Flux
location: class com.nbcu.FluxService
[INFO] 5 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.329 s
[INFO] Finished at: 2016-09-02T15:15:50+05:30
[INFO] Final Memory: 26M/226M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.

请任何人帮助我解决为什么我收到此编译错误

最佳答案

你可以看看compile dependencies needed for Spring Reactor传递依赖 reactor-core-1.1.6-RELEASE 不包含 reactor.core.publisher 包。

我认为你应该包含这个依赖项

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>

而不是这个

<dependency>
<groupId>org.projectreactor</groupId>
<artifactId>reactor-spring</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>

进入reactor-core您可以找到您正在搜索的 Flux

关于带有 REST 服务的 Spring Reactor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39291405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com