我有一个控制器
@Controller
@RequestMapping("/v2/**")
public class ReactController {
@RequestMapping(method = RequestMethod.GET)
public String reactEntry() {
return "react-entry";
}
}
当我登录到应用程序并浏览登录页面,然后导航到点击此URL的页面时,我得到了内容。但是,如果我直接转到URL(它会登录页面,然后直接转发到该URL),则spring返回状态代码200,内容长度为0,而我的控制器永远不会被命中。
在调试日志记录中,通常情况下,我会看到:
[DEBUG] 17 Aug 2018 10:41:50,805 org.springframework.security.web.FilterChainProxy - /v2/ reached end of additional filter chain; proceeding with original chain
[TRACE] 17 Aug 2018 10:41:50,807 org.springframework.web.servlet.DispatcherServlet - Bound request context to thread: SecurityContextHolderAwareRequestWrapper[ org.springframework.security.web.context.HttpSessionSecurityContextRepository Servlet3SaveToSessionRequestWrapper@38f60506]
[DEBUG] 17 Aug 2018 10:41:50,807 org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'cem' processing GET request for [/cems/v2/]
[TRACE] 17 Aug 2018 10:41:50,807 org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@746fb8d3] in DispatcherServlet with name 'cem'
[DEBUG] 17 Aug 2018 10:41:50,807 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /v2/
[TRACE] 17 Aug 2018 10:41:50,842 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Found 1 matching mapping(s) for [/v2/] : [{[/v2/**],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}]
[DEBUG] 17 Aug 2018 10:41:50,842 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public java.lang.String rest.controller.ReactController.reactEntry()]
但是,当通过第二种机制击中时,我得到:
[DEBUG] 17 Aug 2018 10:45:32,702 org.springframework.security.web.FilterChainProxy - /v2/ reached end of additional filter chain; proceeding with original chain
[DEBUG] 17 Aug 2018 10:45:32,779 org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected element of bean 'domain.User': PersistenceElement for transient javax.persistence.EntityManager rest.domain.Personnel.entityManager
注意时间间隔,这表明第二行是另一个请求的一部分。
在第二种情况下,即使请求是相同的URL,也似乎没有将请求映射到cems DispatcherServlet。