简体   繁体   English

Spring Web Reactive 无法作为部署在 Tomcat 8.5 上的 war 文件工作

[英]Spring Web Reactive not working as war file deployed on Tomcat 8.5

I have Spring Boot (2.0.0 M5) application which provides some REST API.我有提供一些 REST API 的 Spring Boot (2.0.0 M5) 应用程序。 I'd like to implement this API using RouterFunction s.我想使用RouterFunction来实现这个 API。

While I'm running app using embedded Jetty everything works fine.当我使用嵌入式 Jetty 运行应用程序时,一切正常。

When I convert the app to WAR file (following documentation here ) and deploy it to Tomcat 8.5 I always get 404 when trying to call any of the endpoints.当我将应用程序转换为 WAR 文件(遵循此处的文档)并将其部署到 Tomcat 8.5 时,我在尝试调用任何端点时总是得到404

I can see in the log that endpoints are recognised:我可以在日志中看到端点被识别:

[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
   }
}

But when calling curl -v http://localhost:8080/demo/say-hello or curl -v http://localhost:8080/demo/api/v1/status I see default Tomcat 404 page.但是当调用curl -v http://localhost:8080/demo/say-hellocurl -v http://localhost:8080/demo/api/v1/status我看到默认的 Tomcat 404 页面。 The path is correct, I rename .war to demo.war before deploying it.路径正确,我在部署之前将 .war 重命名为demo.war

Did anybody come across similar issue?有没有人遇到过类似的问题? You can find the code here .您可以在此处找到代码。

I'm afraid the WAR deployment model is not supported in Spring Boot for WebFlux at the moment.恐怕目前 WebFlux 的 Spring Boot 不支持 WAR 部署模型。 Spring Framework does support that model (although I'm not sure it supports deploying an app to a non-root context). Spring Framework 确实支持该模型(尽管我不确定它是否支持将应用程序部署到非根上下文)。

You can always create an issue on the Spring Boot issue tracker , but I'm not sure this will be implemented, as deploying to a Servlet container is not the primary focus there (and you can't do that with Netty).您始终可以在 Spring Boot 问题跟踪器上创建问题,但我不确定这是否会实现,因为部署到 Servlet 容器不是那里的主要焦点(并且您不能使用 Netty 做到这一点)。

Quick note: adding @EnableWebFlux is a signal that you'd like to take the WebFlux configuration in your own hands and that Spring Boot should not auto-configure things for you in that space.快速说明:添加@EnableWebFlux是一个信号,表明您希望自己掌握 WebFlux 配置,并且 Spring Boot 不应在该空间中为您自动配置内容。

Answering it now just in case some one else is still facing this issue.现在回答它以防万一其他人仍然面临这个问题。

In the POM file, you need to exclude the netty and add tomcat separately.在POM文件中,需要排除netty,单独添加tomcat。

compile ('org.springframework.boot:spring-boot-starter-webflux') {
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter- 
    reactor-netty'
}
compile 'org.springframework.boot:spring-boot-starter-tomcat'

Please check the link for full code : https://github.com/sushantkr16/Spring-boot2-webflux-annotation请检查完整代码的链接: https : //github.com/sushantkr16/Spring-boot2-webflux-annotation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 spring war文件部署到tomcat 9但没有正确重定向? - spring war file deployed to tomcat 9 but not redirecting properly? Spring MVC 部署战争到 tomcat 8.5 - Spring MVC deploy war to tomcat 8.5 Spring 启动 REST 应用程序部署为 tomcat 上的 WAR 不工作 - Spring boot REST application deployed as WAR on tomcat is not working 如何在Spring Boot应用程序中启用HTTPS,该应用程序在Tomcat中作为WAR文件部署? - How to enable HTTPS in a Spring Boot application, deployed as WAR file in Tomcat? 在Tomcat中部署具有战争功能的Hotswap Spring应用程序 - Hotswap Spring Application with war deployed in Tomcat 从部署到已运行的Tomcat 8实例的Spring Boot WAR文件内部获取Tomcat正在运行的端口 - Obtaining the port that Tomcat is running on from inside a Spring Boot WAR file deployed to an already running instance of Tomcat 8 无法在远程Ubuntu Tomcat 8.5上进行战争部署-但在本地Tomcat 8.5上运行 - War deployment on remote Ubuntu tomcat 8.5 not working - but working on local tomcat 8.5 使用 war 将 spring-boot 和 angular 7 应用程序部署到 tomcat 8.5 - Deploy spring-boot and angular 7 application using war into tomcat 8.5 Spring Boot WAR在Tomcat 7中不起作用,但在Tomcat 8中起作用 - Spring Boot WAR not working in Tomcat 7 but working in Tomcat 8 无法在Tomcat管理器中启动已部署的War文件 - Deployed war file not starting in tomcat manager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM