无法运行springboot Web应用程序

时间:2017-11-24 19:16:58

标签: java maven spring-mvc servlets spring-boot

here is my project image

  1. 主类SpringBootHelloWorldApplication.java

            package com.javainuse;
    
                import org.springframework.boot.SpringApplication;
                import org.springframework.boot.autoconfigure.SpringBootApplication;
    
                @SpringBootApplication
                public class SpringBootHelloWorldApplication {
    
                    public static void main(String[] args) {
                        SpringApplication.run(SpringBootHelloWorldApplication.class, args);
                    }
                }
                [project layout][1]
    
    1. 映射TestController.java

              package com.javainuse.controllers;
      
              import org.springframework.stereotype.Controller;
              import org.springframework.ui.Model;
              import org.springframework.ui.ModelMap;
              import org.springframework.web.bind.annotation.RequestMapping;
              import org.springframework.web.servlet.ModelAndView;
      
              @Controller
              public class TestController {
      
                  @RequestMapping("/welcome")
                  public String firstPage(ModelMap map) {
      
                      return "welcome";
                  }
      
              }
      
    2. 的welcome.jsp

          <!DOCTYPE html>
          <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
          <html xmlns:th="http://www.thymeleaf.org">
          <head>
          <title>First Web Application</title>
          </head>
          </html>
      
  2. 4.application.properties

            server.port=8086
            spring.mvc.view.prefix=/WEB-INF/jsp/
            spring.mvc.view.suffix=.jsp
    
        5.pom.xml
    
        <?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
    
            <groupId>com.javainuse</groupId>
            <artifactId>SpringBootHelloWorld</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <packaging>jar</packaging>
    
            <name>SpringBootHelloWorld</name>
            <description>Demo project for Spring Boot</description>
    
            <parent>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>1.4.1.RELEASE</version>
                <relativePath /> <!-- lookup parent from repository -->
            </parent>
    
            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
                <java.version>1.8</java.version>
            </properties>
    
            <dependencies>
    
            <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
    
        </dependency>
    
        <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <optional>true</optional>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
    
    
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-test</artifactId>
                    <scope>test</scope>
                </dependency>
    
                <!-- <dependency>
                    <groupId>org.apache.tomcat.embed</groupId>
                    <artifactId>tomcat-embed-jasper</artifactId>
                </dependency> -->
    
                <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>jstl</artifactId>
                </dependency>
    
                <dependency>
                    <groupId>org.webjars</groupId>
                    <artifactId>bootstrap</artifactId>
                    <version>3.3.7</version>
                </dependency>
    
    
    
            </dependencies>
    
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
    
    
        </project>
    
    6. error in console after hitting http://localhost:8086/welcome
    

    。 ____ _ __ _ _  / \ / &#39; __ _ )_ __ __ _ \ \ \ \ (()_ |&#39; _ |&#39; | |&#39; / `| \ \ \ \  \ / )| | )| | | | | || ( | |))))   &#39; | ____ | | | | | | | __,| / / / / /  ========= | _ | ============== | ___ / = / / / _ /  :: Spring Boot ::(v1.4.1.RELEASE)

    2017-11-24 23:38:08.290 INFO 10028 --- [restartedMain] cjSpringBootHelloWorldApplication:在NITISH上使用PID 10028启动SpringBootHelloWorldApplication(C:\ Users \ sumit \ workspace1 \ SpringBootHelloWorld \ target \ classes由sumit启动C:\ Users \用户SUMIT \工作空间1 \ SpringBootHelloWorld) 2017-11-24 23:38:08.291 INFO 10028 --- [restartedMain] c.j.SpringBootHelloWorldApplication:没有活动的配置文件集,回退到默认配置文件:默认 2017-11-24 23:38:08.296 INFO 10028 --- [restartedMain] ationConfigEmbeddedWebApplicationContext:刷新org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@53707808:启动日期[Fri Nov 24 23:38:08 IST 2017];上下文层次结构的根 2017-11-24 23:38:09.020 INFO 10028 --- [restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer:使用端口初始化的Tomcat:8086(http) 2017-11-24 23:38:09.022 INFO 10028 --- [restartedMain] o.apache.catalina.core.StandardService:启动服务Tomcat 2017-11-24 23:38:09.022 INFO 10028 --- [restartedMain] org.apache.catalina.core.StandardEngine:启动Servlet引擎:Apache Tomcat / 8.5.5 2017-11-24 23:38:09.033 INFO 10028 --- [ost-startStop-1] o.a.c.c.C. [Tomcat]。[localhost]。[/]:初始化Spring嵌入式WebApplicationContext 2017-11-24 23:38:09.034 INFO 10028 --- [ost-startStop-1] o.s.web.context.ContextLoader:Root WebApplicationContext:初始化在738 ms完成 2017-11-24 23:38:09.085 INFO 10028 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean:映射servlet:&#39; dispatcherServlet&#39;至 [/] 2017-11-24 23:38:09.086 INFO 10028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:&#39; characterEncodingFilter&#39;至:[/ ] 2017-11-24 23:38:09.086 INFO 10028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:&#39; hiddenHttpMethodFilter&#39;致:[/ ] 2017-11-24 23:38:09.086 INFO 10028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:&#39; httpPutFormContentFilter&#39;至:[/ ] 2017-11-24 23:38:09.087 INFO 10028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:&#39; requestContextFilter&#39;致:[/ ] 2017-11-24 23:38:09.187 INFO 10028 --- [restartedMain] swsmmaRequestMappingHandlerAdapter:寻找@ControllerAdvice:org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@53707808:启动日期[Fri Nov 24 23:38: 08 IST 2017];上下文层次结构的根 2017-11-24 23:38:09.203 INFO 10028 --- [restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping:Mapped&#34; {[/ welcome]}&#34;到public java.lang.String com.javainuse.controllers.TestController.firstPage(org.springframework.ui.ModelMap) 2017-11-24 23:38:09.207 INFO 10028 --- [restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping:Mapped&#34; {[/ error]}&#34; on public org.springframework.http.ResponseEntity&gt; org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2017-11-24 23:38:09.208 INFO 10028 --- [restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping:Mapped&#34; {[/ error],produce = [text / html]}&#34; on public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 2017-11-24 23:38:09.218 INFO 10028 --- [restartedMain] oswshandler.SimpleUrlHandlerMapping:将URL路径[/ webjars / ]映射到类型为[org.springframework.web.servlet.resource类]的处理程序。 ResourceHttpRequestHandler] 2017-11-24 23:38:09.218 INFO 10028 --- [restartedMain] oswshandler.SimpleUrlHandlerMapping:映射的URL路径[/ ]到[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]类型的处理程序] 2017-11-24 23:38:09.236 INFO 10028 --- [restartedMain] oswshandler.SimpleUrlHandlerMapping:将URL路径[/**/favicon.ico]映射到[class org.springframework.web.servlet.resource]类型的处理程序.ResourceHttpRequestHandler] 2017-11-24 23:38:09.307 INFO 10028 --- [restartedMain] o.s.b.d.a.OptionalLiveReloadServer:LiveReload服务器正在端口35729上运行 2017-11-24 23:38:09.363 INFO 10028 --- [restartedMain] o.s.j.e.a.AnnotationMBeanExporter:在启​​动时为JMX曝光注册bean 2017-11-24 23:38:09.378 INFO 10028 --- [restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer:Tomcat在端口上启动:8086(http) 2017-11-24 23:38:09.381 INFO 10028 --- [restartedMain] c.j.SpringBootHelloWorldApplication:在1.146秒内启动SpringBootHelloWorldApplication(JVM运行63.677) 2017-11-24 23:38:23.373 INFO 10028 --- [nio-8086-exec-1] o.a.c.c.C. [Tomcat]。[localhost]。[/]:初始化Spring FrameworkServlet&#39; dispatcherServlet&#39; 2017-11-24 23:38:23.374 INFO 10028 --- [nio-8086-exec-1] o.s.web.servlet.DispatcherServlet:FrameworkServlet&#39; dispatcherServlet&#39 ;:初始化开始 2017-11-24 23:38:23.377 INFO 10028 --- [nio-8086-exec-1] o.s.web.servlet.DispatcherServlet:FrameworkServlet&#39; dispatcherServlet&#39;:初始化在3毫秒内完成

     > **2017-11-24 23:38:23.386 ERROR 10028 --- [nio-8086-exec-1] org.thymeleaf.TemplateEngine             : **
        > 
        > > [THYMELEAF][http-nio-8086-exec-1] Exception processing template
        > > "welcome": Error resolving template "welcome", template might not
        > > exist or might not be accessible by any of the configured Template
        > > Resolvers 2017-11-24 23:38:23.388 **ERROR 10028 --- [nio-8086-exec-1]
        > > o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for
        > > servlet [dispatcherServlet] in context with path [] threw exception
        > > [Request processing failed; nested exception is
        > > org.thymeleaf.exceptions.TemplateInputException: Error resolving
        > > template "welcome", template might not exist or might not be
        > > accessible by any of the configured Template Resolvers] with root
        > > cause org.thymeleaf.exceptions.TemplateInput**Exception: Error
        > > resolving template "welcome", template might not exist or might not be
        > > accessible by any of the configured Template Resolvers  at
        > > org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:246)
        > > ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]    at
        > > org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104)
        > > ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]    at
        > > org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060)
        > > ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]    at
        > > org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011)
        > > ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]**  at
        > > org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335)
        > > ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]    at
        > > org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:190)
        > > ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]    at
        > > org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)
        > > ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        > 
        > **    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
        > ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]  at
        > org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
        > ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]  at
        > org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
        > ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]  at
        > org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
        > ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]  at
        > org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
        > ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]  at
        > javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
        > ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]  at
        > javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        > ~[tomcat-embed-websocket-8.5.5.jar:8.5.5]     at
        > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        > ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]     at
        > org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        > ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]     at
        > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89)
        > ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]     at
        > org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        > ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]     at
        > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
        > ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]     at
        > org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        > ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]     at
        > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
        > ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]     at
        > org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        > ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]     at
        > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
        > ~[tomcat-embed-core-8.5.5.jar:8.5.5]  at
        > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at
        > java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        > [na:1.8.0_121]    at
        > java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        > [na:1.8.0_121]    at
        > org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        > [tomcat-embed-core-8.5.5.jar:8.5.5]   at java.lang.Thread.run(Unknown
        > Source) [na:1.8.0_121]
    
    
    
    
    
    
    
    
          [1]: https://i.stack.imgur.com/xvYoS.png
    

1 个答案:

答案 0 :(得分:0)

X重命名为welcome.jsp并将文件移至目录welcome.html(如果不存在则创建目录)。默认情况下,从src/main/resources/templates/文件夹中读取百万美元模板。