Spring WebSphere Liberty 上的 MVC,所有 Spring URL 上的 404

Spring MVC on WebSphere Liberty, 404s on all Spring URLs

Eclipse Oxygen with WebSphere Development Tools (WDT),Spring MVC 4.3.14,WebSphere Liberty Core 18.0.0.1 on Java 8. 启用的 Liberty 功能(故意不是最新的)是:

<featureManager>
    <feature>adminCenter-1.0</feature>
    <feature>localConnector-1.0</feature>
    <feature>jaxrs-1.1</feature>
    <feature>concurrent-1.0</feature>
    <feature>webProfile-6.0</feature>
    <feature>jaxb-2.2</feature>
</featureManager>

上下文根上的 JSP 工作正常,所以这是正确的。此外,ibm-web-ext.xml 有 <context-root uri="/webapp/gatewaymvm/" />

Spring 启动日志记录表明我的 @Controller 类 正在绑定到我期望的路径:

10:31:24,102 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:Looking for request mappings in application context: WebApplicationContext for namespace 'Spring MVC Dispatcher-servlet': startup date [Thu Apr 05 10:31:22 CDT 2018]; parent: Root WebApplicationContext
....
10:31:24,125 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:1 request handler methods found on class mypackage.QueryTransactionController: {public mypackage.QueryTransResponse mypackage.QueryTransactionController.processRequest(mypackage.QueryTransRequest,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException={[/QueryTransaction],methods=[POST],consumes=[application/json || application/xml],produces=[application/json || application/xml]}}
10:31:24,125 INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:Mapped "{[/QueryTransaction],methods=[POST],consumes=[application/json || application/xml],produces=[application/json || application/xml]}" onto public mypackage.QueryTransResponse mypackage.QueryTransactionController.processRequest(mypackage.QueryTransRequest,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException
...
10:31:24,130 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:1 request handler methods found on class mypackage.TestPostJSONDocumentController: {public java.lang.String mypackage.TestPostDocumentController.execute(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException={[/testPostJSONDoc],methods=[POST]}}
10:31:24,130 INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:Mapped "{[/testPostJSONDoc],methods=[POST]}" onto public java.lang.String mypackage.TestPostDocumentController.execute(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException

然而,当我点击这些 URL 中的任何一个时,它们会产生 404 响应和如下日志条目:

10:32:40,067 DEBUG org.springframework.web.servlet.DispatcherServlet:DispatcherServlet with name 'Spring MVC Dispatcher' processing POST request for [/webapp/gatewaymvm/testPostJSONDoc]
10:32:40,067 DEBUG org.springframework.webflow.mvc.servlet.FlowHandlerMapping:No flow mapping found for request with URI '/webapp/gatewaymvm/testPostJSONDoc'
10:32:40,068 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:Looking up handler method for path testPostJSONDoc
10:32:40,075 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:Did not find handler method for [testPostJSONDoc]
10:32:40,076 WARN org.springframework.web.servlet.PageNotFound:No mapping found for HTTP request with URI [/webapp/gatewaymvm/testPostJSONDoc] in DispatcherServlet with name 'Spring MVC Dispatcher'

同一个应用程序,当部署到 "Traditional" WAS 时,按预期工作。我想对于 Liberty、Eclipse 下的 Liberty 或 Liberty 下的 Spring MVC,我明显遗漏了一些东西。

在我测试的某个时候,我的代码从当前请求构造了一个 URL,我看到 /webapp/gatewaymvm//resource,两个斜杠在一起。

所以我尝试从上下文根为 /webapp/gatewaymvm/ 的地方删除尾部斜杠,这解决了问题。来自 server.xml 如果我直接安装了 WAR,或者来自 application.xml 如果我在 EAR/Enterprise 项目中安装了 WAR。

有趣的是,JSP 使用尾部斜杠,但 Spring 路径没有。