java – 为什么Spring MVC用404响应并报告“在DispatcherServlet中找不到带有URI […]的HTTP请求的映射”?
我正在编写一个部署在Tomcat上的Spring MVC应用程序.请参阅以下minimal, complete, and verifiable example
public class Application extends AbstractAnnotationConfigDispatcherServletInitializer {
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { };
}
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { SpringServletConfig.class };
}
protected String[] getServletMappings() {
return new String[] { "/*" };
}
}
SpringServletConfig的位置
@Configuration
@ComponentScan("com.example.controllers")
@EnableWebMvc
public class SpringServletConfig {
@Bean
public InternalResourceViewResolver resolver() {
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setPrefix("/WEB-INF/jsps/");
vr.setSuffix(".jsp");
return vr;
}
}
最后,我在com.example.controllers包中有一个@Controller
@Controller
public class ExampleController {
@RequestMapping(path = "/home", method = RequestMethod.GET)
public String example() {
return "index";
}
}
我的应用程序的上下文名称是Example.当我发送请求时
http://localhost:8080/Example/home
应用程序以HTTP状态404响应并记录以下内容
WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI `[/Example/WEB-INF/jsps/index.jsp]` in `DispatcherServlet` with name 'dispatcher'
我在/WEB-INF/jsps/index.jsp上有一个JSP资源我希望Spring MVC能够使用我的控制器来处理请求并转发到JSP,那么为什么它会响应404呢?
对于有关此警告消息的问题,这是一个规范的帖子.