[英]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-hello
或curl -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.