gpt4 book ai didi

java - @GetMapping 和 RSocketServer 与 spring-boot-starter-rsocket

转载 作者:行者123 更新时间:2023-12-02 09:21:14 24 4
gpt4 key购买 nike

正在尝试 https://www.baeldung.com/spring-boot-rsocket 第 4 节中指定的 RSocket 请求/响应。因此,有一个 RSocketServer 自动配置并监听端口 7000。当从浏览器中点击相同的方法时,无法连接到用 @GetMapping 注释的方法

@RestController
public class MarketDataRestController {

private final RSocketRequester rSocketRequester;

public MarketDataRestController(RSocketRequester rSocketRequester) {
this.rSocketRequester = rSocketRequester;
}

@GetMapping(value = "/current/{stock}")
public Publisher<MarketData> current(@PathVariable("stock") String stock) {
return rSocketRequester
.route("currentMarketData")
.data(new MarketDataRequest(stock))
.retrieveMono(MarketData.class);
}
}

期望在从浏览器请求时能够连接到使用 @GetMapping 注释的 MarketDataRestController 类的 current(),例如:http://localhost:7000/current/APPLE 。不确定如何连接到相同的。

最佳答案

您不能使用@RequestMapping对于套接字,请使用 @MessageMapping 代替:

instead of @RequestMapping or @GetMapping annotations like in Spring MVC, we will use the @MessageMapping annotation:

@Controller
public class MarketDataRSocketController {
private final MarketDataRepository marketDataRepository;
public MarketDataRSocketController(MarketDataRepository marketDataRepository) {
this.marketDataRepository = marketDataRepository;
}
@MessageMapping("currentMarketData")
public Mono<MarketData> currentMarketData(MarketDataRequest marketDataRequest) {
return marketDataRepository.getOne(marketDataRequest.getStock());
}

关于java - @GetMapping 和 RSocketServer 与 spring-boot-starter-rsocket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58678666/

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