SpringBoot Web MVC应用程序无法解析视图

时间:2018-03-26 17:49:12

标签: java spring spring-mvc spring-boot

我使用Spring Boot ReST API已有一段时间了;我想过尝试使用web-MVC。但是,我已经陷入了第一部分本身。

我已在GitHub

上传了该项目

到目前为止我做了什么:

  1. 主要定义POM.xml spring-boot-starter-web + tomcat-embed-jasper
  2. 使用@Controller定义@GetMapping("/greeting"),其返回视图名称 - hello
  3. 定义以下属性:

    spring.mvc.view.prefix=/WEB-INF/views/

    spring.mvc.view.suffix=.jsp

  4. hello.jsp

  5. 创建了一个非常基本的观点src/main/web/WEB-INF/views/hello.jsp
  6. 创建了main应用程序以SpringBootApplication运行。
  7. 错误:

      

    Whitelabel错误页面

         

    此应用程序没有明确的映射   /错误,所以你看到这是一个后备。

         

    Mon Mar 26 22:55:03 IST 2018

         

    出现意外错误(type = Not Found,status = 404)。没有可用的消息

    日志:

    2018-03-26 22:55:02.998 DEBUG 7132 --- [nio-8080-exec-1] o.a.coyote.http11.Http11InputBuffer      : Received [GET /greeting HTTP/1.1
    Host: localhost:8080
    Connection: keep-alive
    Cache-Control: max-age=0
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    DNT: 1
    Accept-Encoding: gzip, deflate, br
    Accept-Language: en-US,en;q=0.9,hi;q=0.8
    
    ]
    2018-03-26 22:55:03.043 DEBUG 7132 --- [nio-8080-exec-1] org.apache.tomcat.util.http.Parameters   : Set query string encoding to UTF-8
    2018-03-26 22:55:03.054 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.authenticator.AuthenticatorBase    : Security checking request GET /greeting
    2018-03-26 22:55:03.054 DEBUG 7132 --- [nio-8080-exec-1] org.apache.catalina.realm.RealmBase      :   No applicable constraints defined
    2018-03-26 22:55:03.063 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.a.jaspic.AuthConfigFactoryImpl     : Loading persistent provider registrations from [C:\Users\NirMit\AppData\Local\Temp\tomcat.3836668232954126555.8080\conf\jaspic-providers.xml]
    2018-03-26 22:55:03.064 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.authenticator.AuthenticatorBase    :  Not subject to any constraint
    2018-03-26 22:55:03.067 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing servlet 'dispatcherServlet'
    2018-03-26 22:55:03.068  INFO 7132 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
    2018-03-26 22:55:03.069  INFO 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
    2018-03-26 22:55:03.069 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'multipartResolver'
    2018-03-26 22:55:03.069 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Using MultipartResolver [org.springframework.web.multipart.support.StandardServletMultipartResolver@a8d0be]
    2018-03-26 22:55:03.070 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Creating instance of bean 'org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver'
    2018-03-26 22:55:03.074 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(java.lang.ObjectCustomizer)
    2018-03-26 22:55:03.074 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.077 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolverCustomizer)
    2018-03-26 22:55:03.079 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.082 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(org.springframework.web.servlet.LocaleResolverCustomizer)
    2018-03-26 22:55:03.084 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.084 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Finished creating instance of bean 'org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver'
    2018-03-26 22:55:03.085 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@1c2a3a2]
    2018-03-26 22:55:03.086 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
    2018-03-26 22:55:03.091 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(java.lang.ObjectCustomizer)
    2018-03-26 22:55:03.091 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.093 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(org.springframework.web.servlet.theme.AbstractThemeResolverCustomizer)
    2018-03-26 22:55:03.095 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.097 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(org.springframework.web.servlet.theme.FixedThemeResolverCustomizer)
    2018-03-26 22:55:03.098 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.101 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(org.springframework.web.servlet.ThemeResolverCustomizer)
    2018-03-26 22:55:03.108 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.109 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Finished creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
    2018-03-26 22:55:03.115 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver@1855c21]
    2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'requestMappingHandlerMapping'
    2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'viewControllerHandlerMapping'
    2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'beanNameHandlerMapping'
    2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'resourceHandlerMapping'
    2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'defaultServletHandlerMapping'
    2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'faviconHandlerMapping'
    2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'welcomePageHandlerMapping'
    2018-03-26 22:55:03.117 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'requestMappingHandlerAdapter'
    2018-03-26 22:55:03.117 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'httpRequestHandlerAdapter'
    2018-03-26 22:55:03.117 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'simpleControllerHandlerAdapter'
    2018-03-26 22:55:03.117 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'errorAttributes'
    2018-03-26 22:55:03.117 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'handlerExceptionResolver'
    2018-03-26 22:55:03.121 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
    2018-03-26 22:55:03.124 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(java.lang.ObjectCustomizer)
    2018-03-26 22:55:03.124 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.126 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(org.springframework.web.servlet.view.DefaultRequestToViewNameTranslatorCustomizer)
    2018-03-26 22:55:03.128 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.130 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(org.springframework.web.servlet.RequestToViewNameTranslatorCustomizer)
    2018-03-26 22:55:03.132 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.133 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Finished creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
    2018-03-26 22:55:03.133 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@99d4c6]
    2018-03-26 22:55:03.133 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'beanNameViewResolver'
    2018-03-26 22:55:03.134 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'mvcViewResolver'
    2018-03-26 22:55:03.134 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'defaultViewResolver'
    2018-03-26 22:55:03.134 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'viewResolver'
    2018-03-26 22:55:03.137 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
    2018-03-26 22:55:03.141 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(java.lang.ObjectCustomizer)
    2018-03-26 22:55:03.142 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.143 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(org.springframework.web.servlet.support.AbstractFlashMapManagerCustomizer)
    2018-03-26 22:55:03.146 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.153 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(org.springframework.web.servlet.support.SessionFlashMapManagerCustomizer)
    2018-03-26 22:55:03.156 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.158 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     findClass(org.springframework.web.servlet.FlashMapManagerCustomizer)
    2018-03-26 22:55:03.160 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase       :     --> Returning ClassNotFoundException
    2018-03-26 22:55:03.161 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Finished creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
    2018-03-26 22:55:03.161 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager@3d023d]
    2018-03-26 22:55:03.161 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Published WebApplicationContext of servlet 'dispatcherServlet' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcherServlet]
    2018-03-26 22:55:03.161  INFO 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 92 ms
    2018-03-26 22:55:03.161 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Servlet 'dispatcherServlet' configured successfully
    2018-03-26 22:55:03.177 DEBUG 7132 --- [169.254.165.176] sun.rmi.transport.tcp                    : RMI TCP Connection(3)-169.254.165.176: (port 51150) connection closed
    2018-03-26 22:55:03.177 DEBUG 7132 --- [169.254.165.176] sun.rmi.transport.tcp                    : RMI TCP Connection(3)-169.254.165.176: close connection
    2018-03-26 22:55:03.200 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.w.s.f.OrderedRequestContextFilter  : Bound request context to thread: org.apache.catalina.connector.RequestFacade@1cc2c8
    2018-03-26 22:55:03.211 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/greeting]
    2018-03-26 22:55:03.217 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /greeting
    2018-03-26 22:55:03.223 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public java.lang.String com.khandhedia.sprinboot.mvc.demo1.controller.GreetingController.greetingForm(org.springframework.ui.Model)]
    2018-03-26 22:55:03.223 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'greetingController'
    2018-03-26 22:55:03.224 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/greeting] is: -1
    2018-03-26 22:55:03.285 DEBUG 7132 --- [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-03-26 22:55:03.285 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.servlet.view.BeanNameViewResolver  : No matching bean found for view name 'hello'
    2018-03-26 22:55:03.293 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Invoking afterPropertiesSet() on bean with name 'hello'
    2018-03-26 22:55:03.295 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.web.servlet.view.JstlView: name 'hello'; URL [/WEB-INF/views/hello.jsp]] based on requested media type 'text/html'
    2018-03-26 22:55:03.295 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.web.servlet.view.JstlView: name 'hello'; URL [/WEB-INF/views/hello.jsp]] in DispatcherServlet with name 'dispatcherServlet'
    2018-03-26 22:55:03.296 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.view.JstlView            : Added model object 'name' of type [java.lang.String] to request in view with name 'hello'
    2018-03-26 22:55:03.307 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.view.JstlView            : Forwarding to resource [/WEB-INF/views/hello.jsp] in InternalResourceView 'hello'
    2018-03-26 22:55:03.318 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/WEB-INF/views/hello.jsp]
    2018-03-26 22:55:03.318 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /WEB-INF/views/hello.jsp
    2018-03-26 22:55:03.340 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/WEB-INF/views/hello.jsp]
    2018-03-26 22:55:03.340 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/WEB-INF/views/hello.jsp] are [/**]
    2018-03-26 22:55:03.342 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/WEB-INF/views/hello.jsp] are {}
    2018-03-26 22:55:03.343 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/WEB-INF/views/hello.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@1113a37]]] and 1 interceptor
    2018-03-26 22:55:03.344 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/WEB-INF/views/hello.jsp] is: -1
    2018-03-26 22:55:03.344 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
    2018-03-26 22:55:03.344 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Successfully completed request
    2018-03-26 22:55:03.347 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    :  Disabling the response for further output
    2018-03-26 22:55:03.347 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Successfully completed request
    2018-03-26 22:55:03.347 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.w.s.f.OrderedRequestContextFilter  : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@1cc2c8
    2018-03-26 22:55:03.348 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost]           : Processing ErrorPage[errorCode=0, location=/error]
    2018-03-26 22:55:03.349 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
    2018-03-26 22:55:03.350 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
    2018-03-26 22:55:03.351 DEBUG 7132 --- [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-03-26 22:55:03.351 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'basicErrorController'
    2018-03-26 22:55:03.352 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/error] is: -1
    2018-03-26 22:55:03.354 DEBUG 7132 --- [nio-8080-exec-1] o.s.c.e.PropertySourcesPropertyResolver  : Could not find key 'spring.template.provider.cache' in any property source
    2018-03-26 22:55:03.358 DEBUG 7132 --- [nio-8080-exec-1] o.s.c.e.PropertySourcesPropertyResolver  : Could not find key 'spring.template.provider.cache' in any property source
    2018-03-26 22:55:03.383 DEBUG 7132 --- [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-03-26 22:55:03.383 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'error'
    2018-03-26 22:55:03.383 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Invoking afterPropertiesSet() on bean with name 'error'
    2018-03-26 22:55:03.383 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$SpelView@1943f03] based on requested media type 'text/html'
    2018-03-26 22:55:03.383 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$SpelView@1943f03] in DispatcherServlet with name 'dispatcherServlet'
    2018-03-26 22:55:03.420 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Successfully completed request
    2018-03-26 22:55:03.420 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    :  Disabling the response for further output
    2018-03-26 22:55:03.439 DEBUG 7132 --- [nio-8080-exec-1] o.a.tomcat.util.net.SocketWrapperBase    : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@10910ae:org.apache.tomcat.util.net.NioChannel@4cbd6d:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:51167]], Read from buffer: [0]
    2018-03-26 22:55:03.440 DEBUG 7132 --- [nio-8080-exec-1] o.apache.coyote.http11.Http11Processor   : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@10910ae:org.apache.tomcat.util.net.NioChannel@4cbd6d:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:51167]], Status in: [OPEN_READ], State out: [OPEN]
    2018-03-26 22:55:09.322 DEBUG 7132 --- [nio-8080-exec-5] o.a.tomcat.util.net.SocketWrapperBase    : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@10910ae:org.apache.tomcat.util.net.NioChannel@4cbd6d:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:51167]], Read from buffer: [0]
    2018-03-26 22:55:09.322 DEBUG 7132 --- [nio-8080-exec-5] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
    

    修改

    我根据评论尝试了以下更改;但是,它似乎没有帮助。

    1. hello.jsp放入src/main/resources/templates/WEB-INF/views
    2. hello.jsp放入src/main/resources/static/WEB-INF/views
    3. hello.jsp放入src/main/resources/WEB-INF/views
    4. hello.jsp放入src/main/webapp/WEB-INF/views
    5. 请指教。

2 个答案:

答案 0 :(得分:4)

问题在于Maven Dependency provided的{​​{1}} scope,它用于编译JSP。

对于此maven依赖关系的默认范围,它过得很快!

tomcat-embed-jasper

我分析的两分钱!

当我们已经拥有spring-boot-starter-web时,这种依赖关系的用途是什么?

<!-- Tomcat for JSP rendering --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> 包括spring-boot-starter-webspring-boot-starter-tomcat包含spring-boot-starter-tomcat

但是,tomcat-embed-core并不包含tomcat-embed-core

现在,根据maven docs,如果tomcat-embed-jasper被标记为tomcat-embed-jasper,则表示它需要 JDK 容器< / strong>在运行时提供依赖关系。 此范围仅适用于编译和测试类路径, 不可传递 。 因此,在编译JSP时,有效的依赖性不可用

通过将此依赖关系范围标记为provided,它可以在所有类路径和所有依赖项目中使用。

摘要compile具有spring-boot-starter-web嵌入式依赖项,但它不包含tomcat嵌入式依赖项。需要使用默认的jasper范围添加此依赖项。

将JSP / View组件放在Spring Boot项目中的位置?

  1. 使用Spring Inializr或IntelliJ Spring Plugins创建compile项目。
  2. 使用IDE添加Web框架支持。它可以创建一个目录Web
  3. 将目录从src/main/web/WEB-INF重命名为web
  4. webapp
  5. 创建类似JSP的视图组件
  6. 在application.properties

    中定义以下属性
    src/main/webapp/WEB-INF/views/

答案 1 :(得分:3)

src/main/web/WEB-INF/views/hello.jsp
Spring Boot不会找到

。作为Spring Boot约定,您应该将您的视图放在资源文件夹下:

src/main/resources/templates/...

对于你的CSS:

src/main/resources/static/...

如果您使用的是Spring Boot,那么使用项目初始化程序是个好主意: https://start.spring.io/ 从那里选择你想要的视图技术,Spring Boot会为你添加它的依赖项,所以你不需要添加它们或自己配置它们(步骤3)。