Java RequestMappingHandlerMapping正在截断RestController的路径

Java RequestMappingHandlerMapping正在截断RestController的路径,java,spring,rest,spring-mvc,tomcat,Java,Spring,Rest,Spring Mvc,Tomcat,我似乎对如何将RestController添加到我的应用程序中感到困惑。我离这里很近,但是当点击urlhttp://localhost:8080/rest/username/test我的日志中有以下内容 2015-10-27 20:12:23427 26366[http-nio-8080-exec-5]调试o.s.security.web.FilterChainProxy-/rest/username/test到达附加过滤器链的末尾;继续使用原始链 2015-10-27 20:12:23427

我似乎对如何将RestController添加到我的应用程序中感到困惑。我离这里很近,但是当点击url
http://localhost:8080/rest/username/test
我的日志中有以下内容

2015-10-27 20:12:23427 26366[http-nio-8080-exec-5]调试o.s.security.web.FilterChainProxy-/rest/username/test到达附加过滤器链的末尾;继续使用原始链
2015-10-27 20:12:23427 26366[http-nio-8080-exec-5]调试o.s.web.servlet.DispatcherServlet-名为“Rest”的DispatcherServlet处理获取[/Rest/username/test]请求
2015-10-27 20:12:23427 26366[http-nio-8080-exec-5]调试o.s.w.s.m.m.a.RequestMappingHandlerMapping-查找路径/用户名/测试的处理程序方法
2015-10-27 20:12:23428 26367[http-nio-8080-exec-5]调试o.s.w.s.m.m.a.RequestMappingHandlerMapping-未找到[/username/test]的处理程序方法
2015-10-27 20:12:23428 26367[http-nio-8080-exec-5]调试o.s.w.s.h.SimpleUrlHandlerMapping-请求[/username/test]的匹配模式为[/**]

我发现许多stackoverflow页面由于“点”()而与被截断的路径变量相关,但我的路径没有“点”,现在只返回一个字符串

在我看来,
RequestMappingHandlerMapping
对象在试图找到与适当方法的匹配时正在截断路径。我只是不确定为什么,以及如何让它正常工作

RestController

@RestController 
@RequestMapping(value = "/rest/{username}")
public class RestController {

@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test() {
    return "Rest controller data.";
}

}
@RestController 
@RequestMapping(value = "/{username}")
public class RestController {

@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test() {
return "Rest controller data.";
}

}
web.xml

<servlet-mapping>
    <servlet-name>Rest</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<!-- mvc config -->
<mvc:annotation-driven/>

<!-- scan for controller -->  
<context:component-scan base-package="abnd.pue.rest"/>

休息
/休息/*
rest servlet.xml

<servlet-mapping>
    <servlet-name>Rest</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<!-- mvc config -->
<mvc:annotation-driven/>

<!-- scan for controller -->  
<context:component-scan base-package="abnd.pue.rest"/>

谢谢你的帮助。问题在于上下文路径是一个部署属性,不应将其添加到控制器的映射中

修复

RestController

@RestController 
@RequestMapping(value = "/rest/{username}")
public class RestController {

@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test() {
    return "Rest controller data.";
}

}
@RestController 
@RequestMapping(value = "/{username}")
public class RestController {

@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test() {
return "Rest controller data.";
}

}

不要将上下文路径放在控制器的映射中。这是一个部署属性。您的应用程序不应该知道它。@SotiriosDelimanolis谢谢!