我使用嵌入式tomcat开发了Spring Boot应用程序。然后我需要将其部署到Wildfly10.0.0.Final

两者处理请求的方式似乎非常不同

我在浏览器中输入的URL是:

http://localhost:8181/mywebservices/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123

http://<My_TEST_WF_SERVER>:10080/mywebservices/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123


当我运行spring boot app时,控制台输出看起来像这样,“查找路径的处理程序方法”与上面的路径具有相同的路径,因为它具有上下文根:

> 2018-03-12 16:32:49.996 DEBUG 15252 --- [0.1-8181-exec-1]
> o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name
> 'dispatcherServlet' processing GET request for
> [/mywebservices/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123]
> 2018-03-12 16:32:50.003 DEBUG 15252 --- [0.1-8181-exec-1]
> s.w.s.m.m.a.RequestMappingHandlerMapping : **Looking up handler method
> for path**
> /mywebservices/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123
> 2018-03-12 16:32:50.005 DEBUG 15252 --- [0.1-8181-exec-1]
> s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method
> [public com.comp.mywebservices.domain.model.MLResponse
> com.comp.mywebservices.rest.mywebservicesController.getRequestWithGhostURLs(javax.servlet.http.HttpServletRequest,org.springframework.util.MultiValueMap<java.lang.String,
> java.lang.String>)] 2018-03-12 16:32:50.005 DEBUG 15252 ---
> [0.1-8181-exec-1] o.s.web.servlet.DispatcherServlet        :
> Last-Modified value for
> [/mywebservices/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123]
> is: -1


Wildfly中的日志如下所示,并且path的Lookup处理程序方法在wildfly中没有上下文根:

> 2018-03-12 16:20:40,007 DEBUG
> [org.springframework.web.servlet.DispatcherServlet] (default task-1)
> DispatcherServlet with name 'dispatcherServlet' processing GET request
> for
> [/mywebservices/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123]
> 2018-03-12 16:20:40,031 DEBUG
> [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]
> (default task-1) Looking up handler method for path
> /FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123
> 2018-03-12 16:20:40,034 DEBUG
> [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]
> (default task-1) Did not find handler method for
> [/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123]
> 2018-03-12 16:20:40,035 DEBUG
> [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping]
> (default task-1) Matching patterns for request
> [/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123]
> are [/**] 2018-03-12 16:20:40,036 DEBUG
> [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping]
> (default task-1) URI Template variables for request
> [/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123]
> are {} 2018-03-12 16:20:40,037 DEBUG
> [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping]
> (default task-1) Mapping
> [/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123]
> to HandlerExecutionChain with handler [ResourceHttpRequestHandler
> [locations=[ServletContext resource [/], class path resource
> [META-INF/resources/], class path resource [resources/], class path
> resource [static/], class path resource [public/]],
> resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@64e7e2df]]]
> and 1 interceptor 2018-03-12 16:20:40,038 DEBUG
> [org.springframework.web.servlet.DispatcherServlet] (default task-1)
> Last-Modified value for
> [/mywebservices/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123]
> is: -1 2018-03-12 16:20:40,040 DEBUG
> [org.springframework.web.servlet.DispatcherServlet] (default task-1)
> Null ModelAndView returned to DispatcherServlet with name
> 'dispatcherServlet': assuming HandlerAdapter completed request
> handling 2018-03-12 16:20:40,040 DEBUG
> [org.springframework.web.servlet.DispatcherServlet] (default task-1)
> Successfully completed request


我不确定是什么原因造成的,当我在本地将其作为Spring引导应用程序运行时,nmy应用程序可以正常工作,但是我需要将其部署到Wildfly进行依赖。

我的RestController方法看起来像:

@RequestMapping(value={"/mywebservices/**"},
            method = RequestMethod.GET,
            produces = {"application/vnd.api+json"} )

    public MLResponse getRequestWithGhostURLs(HttpServletRequest request,
                                             @RequestParam MultiValueMap<String,String> multiParams) {

最佳答案

得到一些答案和审判。问题是我引入了Wildfly也需要的jboss-web.xml,并且在那里也定义了上下文根(相同的根),因此对于每个wildfly,第一个是wildfly的上下文根(它省略了)它),然后它在@RequestMapping中查找我的Rest Controller的上下文根,该上下文根在那里不存在,因此它在那里没有看到。。在tomcat / Spring引导中,只有一个容器上下文根,而没有其他。因此,对于Wildfly,我的uRL的工作方式如下:

http://<My_TEST_WF_SERVER>:10080/mywebservices/mywebservices/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123


它的行为正确,因为mywebservices是应用程序的上下文根。由于我只有一个RestController,因此我没有涉及多个上下文根的问题,以防我用不同或相似的注释为第二个上下文根注解。

因此,在这种情况下,我只是从下面删除了mywebservices或从RestController中删除了它。 (两者都有效,我认为从RestController删除它是正确的方法,除非您拥有多个Controller,然后您将在../mywebservices//后附加该控制器的URI映射值

http://<My_TEST_WF_SERVER>:10080/mywebservices/<controller_defined_uri_value>/FinancialTransactions/001/CounterpartyId/111/ClientId/222/MarketIdentifier/MID/SecurityId/333/User/123123


所以我的jboss-web.xml看起来像:

<jboss-web>
    <security-domain>java:/jaas/mywebservicessecurity</security-domain>
    <context-root>mywebservices</context-root>

</jboss-web>

关于tomcat - Tomcat VS Wildfly中不同的URI处理,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49229430/

10-13 09:46