为什么Spring MVC用404响应并报告“在DispatcherServlet中找不到带有URI
我正在编写一个部署在Tomcat上的Spring MVC应用程序。请参阅以下最小,完整且可验证的示例
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")@EnableWebMvcpublic class SpringServletConfig { @Bean public InternalResourceViewResolver resolver() { InternalResourceViewResolver vr = new InternalResourceViewResolver(); vr.setPrefix("/WEB-INF/jsps/"); vr.setSuffix(".jsp"); return vr; }}
最后,我有一个@Controller
包com.example.controllers
@Controllerpublic 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'
我有一个JSP资源,/WEB-INF/jsps/index.jsp
我期望Spring MVC使用我的控制器来处理请求并转发到JSP,那么为什么它会响应404呢?
鸿蒙传说
海绵宝宝撒