我发现以下奇怪的行为:
@Controller
方法)2024-03-14 13:59:49,761 [ajp-nio-172.7.102.11-5067-exec-2] INFO com.mycompany.MyControllerV2 - MyControllerV2 getSomething4() Begin
2024-03-14 13:59:48,048 [ajp-nio-172.7.102.11-5067-exec-1] WARN org.springframework.web.servlet.PageNotFound - No mapping for GET /myapp/functionality/2.0/
2024-03-14 13:57:32,953 [main] DEBUG _org.springframework.web.servlet.HandlerMapping.Mappings -
e.s.a.a.r.c.MyControllerV2:
{GET [/functionality/2.0/{entity}]}: getSomething2(HttpServletRequest,HttpServletResponse)
{GET [/functionality/2.0]}: getSomething4(HttpServletRequest,HttpServletResponse)
{GET [/functionality/2.0/]}: getSomething5(HttpServletRequest,HttpServletResponse)
{GET [/functionality/2.0/pathvalue]}: getSomething6(HttpServletRequest,HttpServletResponse)
{GET [/myapp/functionality/2.0/pathvalue]}: getSomething7(HttpServletRequest,HttpServletResponse)
注意,我有一个版本 1.0,它扩展了普通的旧
HttpServlet
,因此需要这个 /2.0/
路径组件。
<servlet>
<servlet-name>NEWAPI</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>dispatchOptionsRequest</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>NEWAPI</servlet-name>
<url-pattern>/functionality/2.0/*</url-pattern>
</servlet-mapping>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!--
- The controllers are autodetected POJOs labeled with the @Controller annotation.
-->
<context:component-scan base-package="edu.mycompany" />
</beans>
(强制,不是我的选择)
@RequestMapping
@Controller 中的 url 必须(通常)应该相对于根 url 模式。
如果 Spring 请求映射中的 url 与 web.xml 模式相同,它将作为绝对 url 成功匹配。否则,url 的两个组成部分不应重叠。