代码之家  ›  专栏  ›  技术社区  ›  Mayank Kumar Thakur

无法使用嵌入的tomcat服务器在springboot中运行控制器类处理程序方法

  •  0
  • Mayank Kumar Thakur  · 技术社区  · 3 年前

    我创建了一个简单的控制器类处理程序方法来运行jsp类型的文件。 我创造了一个TestController.java测试控制器文件有我的处理程序方法

    package com.practice.myapp;
    
    import javax.servlet.http.HttpServletRequest;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    public class TestController {
       @RequestMapping("/")
       @ResponseBody
       public String handler(HttpServletRequest request) {
           
           return "this is fun and awesome";
       }
    
       @RequestMapping("/home")
       public String home(){
           System.out.println("this is Home");
    
           return "home";
       }
    
    }
    
    

    应用程序属性-

    spring.mvc.view.prefix= /views/
    spring.mvc.view.suffix=.jsp
    
    

    为了在控制器中使用jsp文件,我在src/main中创建了一个webapp文件夹,其中有一个包含jsp视图文件的文件夹视图。

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%-- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ page isELIgnored="false"%> --%>
    <!doctype html>
    <html lang="en">
    <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    
    <title>Hello, world!</title>
    </head>
    <body>
        <h1> this is head </h1>
        
    </body>
    </html>
    

    我还添加了tomcat嵌入的jasper maven依赖项来运行我的jsp文件。 这是我POM的链接。 https://ide.geeksforgeeks.org/tryit.php/cOtzkizjYD

      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::                (v2.4.4)
    
    2021-03-29 01:43:49.289  INFO 33924 --- [  restartedMain] com.practice.myapp.MyappApplication      : Starting MyappApplication using Java 15.0.1 on LAPTOP-RP0N4VRN with PID 33924 (F:\Project2020\SpringBootinVSCode\myapp\target\classes started by hp in F:\Project2020\SpringBootinVSCode\myapp)
    2021-03-29 01:43:49.295  INFO 33924 --- [  restartedMain] com.practice.myapp.MyappApplication      : No active profile set, falling back to default profiles: default
    2021-03-29 01:43:49.432  INFO 33924 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
    2021-03-29 01:43:49.432  INFO 33924 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
    2021-03-29 01:43:50.539  INFO 33924 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$1a01da0f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2021-03-29 01:43:50.633  INFO 33924 --- [  restartedMain] .w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
    2021-03-29 01:43:51.367  INFO 33924 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
    2021-03-29 01:43:51.404  INFO 33924 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2021-03-29 01:43:51.404  INFO 33924 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.44]
    2021-03-29 01:43:51.672 ERROR 33924 --- [  restartedMain] org.apache.catalina.core.ContainerBase   : A child container failed during start
    
    

    0 回复  |  直到 3 年前