我有提供一些 REST API 的 Spring Boot (2.0.0 M5) 应用程序。我想使用 RouterFunction
实现这个 API。
当我使用嵌入式 Jetty 运行应用程序时,一切正常。
当我将应用程序转换为 WAR 文件(在 documentation here 之后)并将其部署到 Tomcat 8.5 时,我在尝试调用任何端点时总是得到 404
。
我可以在日志中看到端点已被识别:
[ost-startStop-1] s.w.r.r.m.a.RequestMappingHandlerMapping : Mapped "{[/say-hello],methods=[GET]}" onto java.lang.String com.example.demo.DemoController.test()
[ost-startStop-1] o.s.w.r.f.s.s.RouterFunctionMapping: Mapped /api => {
/v1 => {
/status ->
com.example.demo.DemoApplication$$Lambda$189/1904651750@5fdc83e
}
}
但是当调用 curl -v http://localhost:8080/demo/say-hello
或 curl -v http://localhost:8080/demo/api/v1/status
我看到默认的 Tomcat 404 页面。路径是正确的,我在部署之前将 .war 重命名为 demo.war
。
有人遇到过类似的问题吗?您可以找到代码 here .
最佳答案
恐怕目前 WebFlux 的 Spring Boot 不支持 WAR 部署模型。 Spring Framework 确实支持该模型(尽管我不确定它是否支持将应用程序部署到非根上下文)。
您始终可以在 the Spring Boot issue tracker 上创建问题,但我不确定这是否会实现,因为部署到 Servlet 容器并不是那里的主要焦点(你不能用 Netty 做到这一点)。
快速说明:添加 @EnableWebFlux
是一个信号,表明您希望自己掌握 WebFlux 配置,并且 Spring Boot 不应在该空间为您自动配置。
关于java - Spring Web Reactive 不能作为部署在 Tomcat 8.5 上的 war 文件工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46714809/