Spring Boot viewResolver 不起作用 - 未映射到给定位置 [英] Spring Boot viewResolver not working - not mapping to given location

查看:17
本文介绍了Spring Boot viewResolver 不起作用 - 未映射到给定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于学习的 Spring Boot 应用程序.

I am developing spring boot application for learning.

@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/views/");
    resolver.setSuffix(".jsp");
    registry.viewResolver(resolver);
}

我已经按照上面给出的方式配置了我的视图解析器.下面是页面的 API 端点

I have configured my view resolver as given above. And below is the API endpoint for page

@RequestMapping(value = "/",method = RequestMethod.GET)
public ModelAndView homePage(){
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("index");
    return modelAndView;
}

但是当我点击这个 api 时,我无法得到响应.我得到 404我在控制台上得到的错误是在名称为dispatcherServle"的 DispatcherServlet 中未找到具有 URI [/WEB-INF/views/index.jsp] 的 HTTP 请求的映射

But when i hit this api, i am unable to get a response. I get 404 and error i get on console is No mapping found for HTTP request with URI [/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dispatcherServle

我该如何解决这个问题?

How can i fix this ?

推荐答案

适用于为此类问题而苦苦挣扎的人们 - Spring Boot 文档指出 此处 在可嵌入 servlet 容器中运行时不支持 JSP - 即使用时JAR 包装.

for people struggling with issues like this - the Spring Boot documentation states here that JSPs are not supported when running in embeddable servlet container - i.e. when using JAR packaging.

当使用 WAR 打包时,这里的答案中给出的建议应该有效 - 但请检查在最终 WAR 中的根目录是否存在:WEB-INF/views,以及您的 JSP

when using WAR packaging, the suggestion given in the answers here should work - but check that in the final WAR there is a directory at root: WEB-INF/views, with your JSPs

这篇关于Spring Boot viewResolver 不起作用 - 未映射到给定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆