SpringBoot找不到视图

时间:2018-07-06 09:05:09

标签: java maven spring-boot

我正在尝试编写一个简单的SpringBoot Web应用程序以开始使用该框架。

这是我的结构:

src
`-main
   `-java
   `-resources
     `-static
     `-templates
   `-webapp
     `-WEB-INF
        `-jsp
            `-login.jsp 

我有一个像这样的控制器

@Controller
public class LoginController {

    @RequestMapping("/login")
    public String loginMessage(){
        return "login";
    }
}

我已经在application.properties中配置了必须在其中查找视图的路径,

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
logging.level.org.springframework.web=DEBUG

我还在pom.xml中包括了下一个依赖项:

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>

但是当我转到http://localhost:8080/login时,我仍然遇到404错误。 我想念什么?

编辑: 这是IntelliJ Idea控制台的日志。似乎找到了login.jsp,但由于某种原因返回了错误页面。

2018-07-06 11:17:20.488 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/login]
2018-07-06 11:17:20.488 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /login
2018-07-06 11:17:20.488 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public java.lang.String com.albertocastano.apringboot.web.springbootfirstwebapplication.controller.LoginController.loginMessage()]
2018-07-06 11:17:20.488 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/login] is: -1
2018-07-06 11:17:20.489 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, */*;q=0.8] based on Accept header types and producible media types [*/*])
2018-07-06 11:17:20.489 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.servlet.view.BeanNameViewResolver  : No matching bean found for view name 'login'
2018-07-06 11:17:20.489 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.web.servlet.view.InternalResourceView: name 'login'; URL [/WEB-INF/jsp/login.jsp]] based on requested media type 'text/html'
2018-07-06 11:17:20.489 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.web.servlet.view.InternalResourceView: name 'login'; URL [/WEB-INF/jsp/login.jsp]] in DispatcherServlet with name 'dispatcherServlet'
2018-07-06 11:17:20.492 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView  : Forwarding to resource [/WEB-INF/jsp/login.jsp] in InternalResourceView 'login'
2018-07-06 11:17:20.492 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/WEB-INF/jsp/login.jsp]
2018-07-06 11:17:20.492 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /WEB-INF/jsp/login.jsp
2018-07-06 11:17:20.493 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/WEB-INF/jsp/login.jsp]
2018-07-06 11:17:20.495 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/WEB-INF/jsp/login.jsp] are [/**]
2018-07-06 11:17:20.496 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/WEB-INF/jsp/login.jsp] are {}
2018-07-06 11:17:20.497 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/WEB-INF/jsp/login.jsp] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@3f0408]]] and 1 interceptor
2018-07-06 11:17:20.498 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/WEB-INF/jsp/login.jsp] is: -1
2018-07-06 11:17:20.499 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2018-07-06 11:17:20.499 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2018-07-06 11:17:20.500 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2018-07-06 11:17:20.501 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
2018-07-06 11:17:20.502 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2018-07-06 11:17:20.502 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)]
2018-07-06 11:17:20.502 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/error] is: -1
2018-07-06 11:17:20.522 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, text/html;q=0.8] based on Accept header types and producible media types [text/html])
2018-07-06 11:17:20.522 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$SpelView@bd7588] based on requested media type 'text/html'
2018-07-06 11:17:20.522 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$SpelView@bd7588] in DispatcherServlet with name 'dispatcherServlet'
2018-07-06 11:17:20.522 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Successfully completed request

1 个答案:

答案 0 :(得分:1)

您在pom.xml文件中缺少依赖项。

添加jstl:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>

并删除provided的作用域tomcat-embed-jasper,因为任何spring-boot-starter都不默认提供它。