tomcat VS Wildfly中的不同URI处理

时间:2018-03-12 06:42:15

标签: tomcat spring-boot wildfly-10

我使用嵌入式tomcat开发了我的Spring启动应用程序。然后我需要它在Wildfly10.0.0.Final上部署

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

我在浏览器中点击的网址是:

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时,控制台输出如下所示,&#34;查找处理程序方法的路径&#34;与上面的路径具有相同的路径,因为它具有上下文根:

> 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中的日志如下所示,路径的查找处理程序方法在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 app工作正常,但我需要部署到Wildfly以获取依赖关系。

我的RestController方法如下:

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

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

1 个答案:

答案 0 :(得分:0)

得到了一些命中和试验的答案。问题是我引入了Wildfly也需要的jboss-web.xml,我也在那里定义了上下文根(同一个),因为对于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>