Spring mvc @带斜杠的RequestMapping无法返回视图

Spring mvc @带斜杠的RequestMapping无法返回视图,spring-mvc,Spring Mvc,我有一个愚蠢的问题,我不知道为什么会发生这种情况——如果我的映射中有斜杠,视图分辨率就会失败;我有一个控制器: import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @Controller public

我有一个愚蠢的问题,我不知道为什么会发生这种情况——如果我的映射中有斜杠,视图分辨率就会失败;我有一个控制器:

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class PartialsController {

  @RequestMapping ("/views/partials/{view}") // Doesn't work!
  public String partial (@PathVariable ("view") String view) {
    System.out.println ("\n\nVIEW=\"" + view + "\"\n\n");
    return "partials/" + view;
  }

  @RequestMapping ("/partial-{view}-view") // Works!!!
  public String test (@PathVariable ("view") String view) {
    return partial (view);
  }

  @RequestMapping ("/views/partials/{view}/show.html") // Doesn't work!
  public String test2 (@PathVariable ("view") String view) {
    return partial (view);
  }
}
完整堆栈跟踪在这里:这是它的顶部我看到我的系统。在每种情况下:

[DEBUG] : Could not complete request
java.lang.NullPointerException
at java.net.URLEncoder.encode(URLEncoder.java:205)
at java.net.URLEncoder.encode(URLEncoder.java:171)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:474)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669)
    ...
我真的很想使用第一种方法,它只是对我所做的更有意义;非常感谢您的帮助

注意:忘了添加,这是我的Java配置:

@Override
public void onStartup (ServletContext servletContext) throws ServletException {
  AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext ();
  mvcContext.register (MvcConfiguration.class);
  Dynamic dispatcher = servletContext.addServlet ("dispatcher", new DispatcherServlet (mvcContext));
  dispatcher.setLoadOnStartup (1);
  dispatcher.addMapping ("/");
}
试试这个:

 @Override
public void onStartup (ServletContext servletContext) throws ServletException {
  AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext ();
  mvcContext.register (MvcConfiguration.class);
  Dynamic dispatcher = servletContext.addServlet ("dispatcher", new DispatcherServlet (mvcContext));
  dispatcher.setLoadOnStartup (1);
  dispatcher.addMapping ("/*"); //<- It will dispatch all URLs, not only those which starts with /
}

事实上,我找到了答案,键入一个响应让我认为我的JSP视图解析器设置有问题,事实上存在以下问题:

@Bean (name = "jspViewResolver")
public ViewResolver jspViewResolver () {
  return new InternalResourceViewResolver () {
    {
      setPrefix ("/META-INF/resources/mev/views/");
      setSuffix (".jsp");
      setOrder (2);
      setExposeContextBeansAsAttributes (true);
    }
  };
}

在META-INF之前,我没有斜杠。是的,我的观点有点奇怪。无论如何,谢谢

我试过了,我只是得到了一个直接的404然后-没有找到映射。这对我来说也是有意义的,因为我认为星星意味着所有的映射,直到另一条斜线。问题不在于映射本身有多个斜杠,而是与一个视图结合在一起,因为我在应用程序的其他地方有多个斜杠的映射,返回JSON@ResponseBy,所以没有视图解析,一切都正常工作,而且有斜杠的控制器也会被调用,我确实看到了我放在其中的任何日志记录,所以任何出错的东西从控制器返回后都会出错。