春季启动:我正在获得whitelabel错误pae而不是视图

时间:2018-09-15 09:36:44

标签: spring jsp spring-boot model-view-controller

我正在用Spring MVC和H2在内存数据库中编写Spring Boot应用程序。我有一个在 findAllPosts()方法上映射/ posts的控制器,该方法返回 post.jsp 视图。但是,当我运行应用程序并点击localhost:8080 / posts时,它显示错误页面。在控制台中,它还显示了/ posts的映射。

控制器类-

package com.H2DatabaseDemo.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.H2DatabaseDemo.model.Post;
import com.H2DatabaseDemo.services.PostService;
@Controller
public class H2DemoController {
    @Autowired
    private PostService postService;
    @RequestMapping("/posts")
    public String findAllPost(Model model)
    {
        List<Post> thePosts=postService.findAllPost();
        model.addAttribute("posts",thePosts);
        return "posts";
    }
}

应用类别-

package com.H2DatabaseDemo;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class H2DatabaseDemoApplication {
public static void main(String[] args) {
        SpringApplication.run(H2DatabaseDemoApplication.class, args);
    }
}

属性文件-

spring.h2.console.enabled=true
spring.h2.console.path=/console
spring.datasource.url=jdbc:h2:mem:h2demo-app
spring.mvc.view.prefix: /WEB-INF/view/
spring.mvc.view.suffix: .jsp

堆栈跟踪-

 :: Spring Boot ::        (v2.0.4.RELEASE)

2018-09-16 09:19:50.379  INFO 12868 --- [           main] c.H.H2DatabaseDemoApplication            : Starting H2DatabaseDemoApplication on DESKTOP-7NILS0D with PID 12868 (D:\springCourse\H2DatabaseDemo\target\classes started by Mrugesh in D:\springCourse\H2DatabaseDemo)
2018-09-16 09:19:50.384  INFO 12868 --- [           main] c.H.H2DatabaseDemoApplication            : No active profile set, falling back to default profiles: default
2018-09-16 09:19:50.459  INFO 12868 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3d299e3: startup date [Sun Sep 16 09:19:50 IST 2018]; root of context hierarchy
2018-09-16 09:19:52.000  INFO 12868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$74090544] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-09-16 09:19:52.796  INFO 12868 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-09-16 09:19:52.833  INFO 12868 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-09-16 09:19:52.834  INFO 12868 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.32
2018-09-16 09:19:52.849  INFO 12868 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_171\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_171/bin/server;C:/Program Files/Java/jre1.8.0_171/bin;C:/Program Files/Java/jre1.8.0_171/lib/amd64;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\nodejs\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Microsoft VS Code\bin;C:\Users\Mrugesh\AppData\Roaming\npm;C:\Users\Mrugesh\AppData\Local\Microsoft\WindowsApps;C:\Users\Mrugesh\AppData\Local\GitHubDesktop\bin;C:\eclipse;;.]
2018-09-16 09:19:53.018  INFO 12868 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-09-16 09:19:53.018  INFO 12868 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2562 ms
2018-09-16 09:19:53.160  INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-09-16 09:19:53.162  INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet webServlet mapped to [/console/*]
2018-09-16 09:19:53.167  INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-09-16 09:19:53.167  INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-09-16 09:19:53.168  INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-09-16 09:19:53.168  INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-09-16 09:19:53.408  INFO 12868 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2018-09-16 09:19:53.806  INFO 12868 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2018-09-16 09:19:53.876  INFO 12868 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-09-16 09:19:53.905  INFO 12868 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-09-16 09:19:54.036  INFO 12868 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.17.Final}
2018-09-16 09:19:54.038  INFO 12868 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-09-16 09:19:54.085  INFO 12868 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-09-16 09:19:54.280  INFO 12868 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2018-09-16 09:19:54.962  INFO 12868 --- [           main] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@93824eb'
2018-09-16 09:19:54.965  INFO 12868 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-09-16 09:19:55.623  INFO 12868 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-16 09:19:55.918  INFO 12868 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3d299e3: startup date [Sun Sep 16 09:19:50 IST 2018]; root of context hierarchy
2018-09-16 09:19:55.974  WARN 12868 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-09-16 09:19:56.017  INFO 12868 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/posts]}" onto public java.lang.String com.H2DatabaseDemo.controller.H2DemoController.findAllPost(org.springframework.ui.Model)
2018-09-16 09:19:56.027  INFO 12868 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-09-16 09:19:56.028  INFO 12868 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-09-16 09:19:56.060  INFO 12868 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-16 09:19:56.060  INFO 12868 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-16 09:19:56.366  INFO 12868 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-09-16 09:19:56.370  INFO 12868 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-09-16 09:19:56.378  INFO 12868 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-09-16 09:19:56.610  INFO 12868 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-09-16 09:19:56.614  INFO 12868 --- [           main] c.H.H2DatabaseDemoApplication            : Started H2DatabaseDemoApplication in 6.721 seconds (JVM running for 7.372)
2018-09-16 09:20:06.742  INFO 12868 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-09-16 09:20:06.742  INFO 12868 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2018-09-16 09:20:06.884  INFO 12868 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 142 ms
2018-09-16 09:20:07.138  INFO 12868 --- [nio-8080-exec-1] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory

2 个答案:

答案 0 :(得分:0)

在控制器方法上添加RequestMapping(“ /”)

答案 1 :(得分:0)

请在您的pom.xml中添加这些依赖项

<dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jstl</artifactId>
</dependency>