Spring MVC на WebSphere Liberty, 404 с на всех URL-адресах Spring

Eclipse Oxygen с инструментами разработки WebSphere (WDT), Spring MVC 4.3.14, WebSphere Liberty Core 18.0.0.1 на 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'

Это же приложение при развертывании в "традиционном" WAS работает как положено. Я полагаю, что есть что-то очевидное, что мне не хватает в Liberty, Liberty в Eclipse или Spring MVC в Liberty.

1 ответ

Решение

В какой-то момент во время моего тестирования, когда у меня был код, который создал URL из текущего запроса, я видел /webapp/gatewaymvm//resource, с двумя косыми чертами вместе.

Поэтому я попытался удалить косую черту из тех мест, где у меня был контекстный корень /webapp/gatewaymvm/и это решило проблему. Либо из server.xml если я установил там WAR напрямую или из application.xml если у меня установлена ​​WAR в проекте EAR/Enterprise.

Интересно, что JSP там работали с конечной косой чертой, а пути Spring - нет.

Другие вопросы по тегам