為什么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呢?
為什么Spring MVC用404響應并報告“在DispatcherServlet中找不到帶有URI
繁花如伊
2019-05-22 14:04:17