【问题标题】:not able to run springboot web application无法运行 Spring Boot Web 应用程序
【发布时间】:2018-05-08 19:18:29
【问题描述】:

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>
      

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

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

2017-11-24 23:38:08.290 INFO 10028 --- [restartedMain] cjSpringBootHelloWorldApplication:在 NITISH 上启动 SpringBootHelloWorldApplication,PID 为 10028(C:\Users\sumit\workspace1\SpringBootHelloWorld\target\classes 由 sumit 启动C:\Users\smit\workspace1\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] os.web.context.ContextLoader:根 WebApplicationContext:初始化在 738 毫秒内完成 2017-11-24 23:38:09.085 信息 10028 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean:映射 servlet:'dispatcherServlet' 到 [/] 2017-11-24 23:38:09.086 INFO 10028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'characterEncodingFilter' 到:[/] 2017-11-24 23:38:09.086 INFO 10028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'hiddenHttpMethodFilter' 到:[/] 2017-11-24 23:38:09.086 INFO 10028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:“httpPutFormContentFilter”到:[/] 2017-11-24 23:38:09.087 信息 10028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'requestContextFilter' 到:[/] 2017-11-24 23:38:09.187 INFO 10028 --- [restartedMain] swsmmaRequestMappingHandlerAdapter:寻找@ControllerAdvice:org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@53707808:启动日期[11 月 24 日星期五 23:38: 08 IST 2017];上下文层次的根 2017-11-24 23:38:09.203 INFO 10028 --- [restartedMain] swsmmaRequestMappingHandlerMapping:将“{[/welcome]}”映射到公共 java.lang.String com.javainuse.controllers.TestController.firstPage(org.springframework .ui.ModelMap) 2017-11-24 23:38:09.207 INFO 10028 --- [restartedMain] swsmmaRequestMappingHandlerMapping:将“{[/error]}”映射到公共 org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web。 BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2017-11-24 23:38:09.208 INFO 10028 --- [restartedMain] swsmmaRequestMappingHandlerMapping:将“{[/error],produces=[text/html]}”映射到公共 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/] 映射到 [class org.springframework.web.servlet.resource.资源HttpRequestHandler] 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 'dispatcherServlet' 2017-11-24 23:38:23.374 INFO 10028 --- [nio-8086-exec-1] os.web.servlet.DispatcherServlet:FrameworkServlet 'dispatcherServlet':初始化开始 2017-11-24 23:38:23.377 INFO 10028 --- [nio-8086-exec-1] os.web.servlet.DispatcherServlet:FrameworkServlet 'dispatcherServlet':初始化在 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

【问题讨论】:

  • welcome.jsp 这对我来说看起来不像 Thymeleaf 模板。看起来您正在混合 JSP 和 Thymeleaf。
  • 能否提供指定视图解析器的 appconfig 类?
  • 请给我们一个帮助你的理由,首先要展示一些调试工作。
  • @RomanPuchkovskiy 即使我通过删除 org.springframework.bootspring-boot-starter-thymeleaf 更改了我的 pom.xml /dependency> 我得到这个应用程序没有明确的 /error 映射,因此您将其视为后备。 IST 2017 年 11 月 25 日星期六 01:24:33 出现意外错误(类型=未找到,状态=404)。没有可用的消息。

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


【解决方案1】:

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

【讨论】:

  • 我的项目现在开始工作了。我不再使用 thymeleaf 了。我刚刚清除了我的存储库并尝试在 Eclipse 中使用 maven install 进行安装...仅存储库文件夹存在一些问题...谢谢:)
猜你喜欢
  • 1970-01-01
  • 2020-10-03
  • 2019-05-02
  • 1970-01-01
  • 2020-11-06
  • 2017-05-30
  • 2018-05-13
  • 2020-04-20
  • 2020-02-22
相关资源
最近更新 更多