Spring Web Reactive 无法作为部署在 Tomcat 8.5 上的 war 文件运行
Spring Web Reactive not working as war file deployed on Tomcat 8.5
我有 Spring Boot (2.0.0 M5) 应用程序,它提供了一些 REST API。我想使用 RouterFunction
s.
来实现这个 API
当我 运行 应用程序使用嵌入式 Jetty 时,一切正常。
当我将应用程序转换为 WAR 文件(在 documentation here 之后)并将其部署到 Tomcat 8.5 时,我总是在尝试调用任何端点。
我可以在日志中看到端点已被识别:
[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$$Lambda9/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.
恐怕 WAR 部署模型目前在 Spring Boot for WebFlux 中不受支持。 Spring 框架确实支持该模型(尽管我不确定它是否支持将应用程序部署到非根上下文)。
您始终可以在 the Spring Boot issue tracker 上创建问题,但我不确定这是否会实现,因为部署到 Servlet 容器不是那里的主要焦点(而且您不能通过网络)。
快速说明:添加 @EnableWebFlux
表示您希望自己掌握 WebFlux 配置,Spring Boot 不应为您自动配置 space.
现在回答它以防其他人仍然面临这个问题。
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'
请检查 link 以获得完整代码:https://github.com/sushantkr16/Spring-boot2-webflux-annotation
我有 Spring Boot (2.0.0 M5) 应用程序,它提供了一些 REST API。我想使用 RouterFunction
s.
当我 运行 应用程序使用嵌入式 Jetty 时,一切正常。
当我将应用程序转换为 WAR 文件(在 documentation here 之后)并将其部署到 Tomcat 8.5 时,我总是在尝试调用任何端点。
我可以在日志中看到端点已被识别:
[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$$Lambda9/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.
恐怕 WAR 部署模型目前在 Spring Boot for WebFlux 中不受支持。 Spring 框架确实支持该模型(尽管我不确定它是否支持将应用程序部署到非根上下文)。
您始终可以在 the Spring Boot issue tracker 上创建问题,但我不确定这是否会实现,因为部署到 Servlet 容器不是那里的主要焦点(而且您不能通过网络)。
快速说明:添加 @EnableWebFlux
表示您希望自己掌握 WebFlux 配置,Spring Boot 不应为您自动配置 space.
现在回答它以防其他人仍然面临这个问题。
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'
请检查 link 以获得完整代码:https://github.com/sushantkr16/Spring-boot2-webflux-annotation