【问题标题】:Java: Eclipse console doesn't display Spring Controller informationJava:Eclipse 控制台不显示 Spring Controller 信息
【发布时间】:2019-04-28 01:31:29
【问题描述】:

当我在 Eclipse 4.7.3 IDE 中运行我的 spring boot 应用程序时,控制台不显示有关 rest 控制器的信息。然而,当我用浏览器测试它时,控制器正在工作。

它只是一个“Hello World”应用程序:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HelloWorldSpringBootApp {

    public static void main(String[] args) {
        SpringApplication.run(HelloWorldSpringBootApp.class, args);
    }

}


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {

    @RequestMapping(value = "/")
    public String helo() {
        return "Hello World!";
    }
}

输出:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.4.RELEASE)

2019-04-28 09:08:33.768  INFO 2208 --- [           main] c.infotech.app.HelloWorldSpringBootApp   : Starting HelloWorldSpringBootApp on OfficeLaptop01 with PID 2208 (C:\Users\Admin\eclipse-workspace4.7.3a\Sprang\HelloWorldSpringBoot\target\classes started by Admin in C:\Users\Admin\eclipse-workspace4.7.3a\Sprang\HelloWorldSpringBoot)
2019-04-28 09:08:33.775  INFO 2208 --- [           main] c.infotech.app.HelloWorldSpringBootApp   : No active profile set, falling back to default profiles: default
2019-04-28 09:08:34.852  INFO 2208 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-04-28 09:08:34.873  INFO 2208 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-04-28 09:08:34.873  INFO 2208 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-04-28 09:08:34.978  INFO 2208 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-04-28 09:08:34.978  INFO 2208 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1157 ms
2019-04-28 09:08:35.183  INFO 2208 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-28 09:08:35.348  INFO 2208 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-04-28 09:08:35.351  INFO 2208 --- [           main] c.infotech.app.HelloWorldSpringBootApp   : Started HelloWorldSpringBootApp in 1.904 seconds (JVM running for 2.561)

如上所示,它只显示“在 1.904 秒内启动 HelloWorldSpringBootApp”,而没有请求映射状态和映射的 URL 路径信息。为什么?

【问题讨论】:

  • 尝试调试级别日志以及您正在查看的确切信息是什么?

标签: java eclipse spring-boot servlets


【解决方案1】:

log output was changed in Spring 2.1。该变更日志指出

如果您尝试调试应用程序并且想要恢复 Spring Boot 2.0 风格的日志记录,您应该将以下内容添加到您的 application.properties

logging.level.web=debug

但是,鉴于此RestController,此更改不会输出我所期望的结果

@RestController
public class HelloWorldController {

    @RequestMapping(value = "/hello")
    public String hello() {
        return "Hello World!";
    }
}

如果我将日志级别设置为 trace,它会给出预期的输出(尽管与 Spring Boot 2.1 的方式不同)。

10:53:26.427 [main] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping - 
    c.i.e.d.r.HelloWorldController:
    { /hello}: hello()

trace 日志级别的要求很可能是由于 Spring Framework 5.1 中的更改(请参阅release note

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    相关资源
    最近更新 更多