gpt4 book ai didi

java - Spring Boot 2.0.0.M2如何在@Bean方法中注册RouterFunction?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:21:39 24 4
gpt4 key购买 nike

我正在尝试使用 Spring 5 的功能,但在注册 RouterFunction 时遇到了一些问题,它会被读取,但不会被映射。 (尝试在方法中抛出异常。)

@Configuration
@RequestMapping("/routes")
public class Routes {
@Bean
public RouterFunction<ServerResponse> routingFunction() {
return RouterFunctions.route(RequestPredicates.path("/asd"), req -> ok().build());
}
}

转到 /routes/asd 结果是 404,关于我做错了什么的任何线索?(我也试过没有这个 @RequestMapping/routes,它也为 /asd 返回 404)

最佳答案

我发现了问题。

我的 pom.xml 中都有这些依赖项:

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

删除了 spring-boot-starter-web 依赖项,webflux 开始正常工作。

另一种解决方案是保留 web 依赖性并排除 tomcat,以便 netty 开始工作:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

关于java - Spring Boot 2.0.0.M2如何在@Bean方法中注册RouterFunction?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44774261/

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