Java: Eclipse 控制台不显示 Spring 控制器信息

Java: Eclipse console doesn't display Spring Controller information

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

这只是一个 "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)

如上所述,它只显示直到 "Started HelloWorldSpringBootApp in 1.904 seconds",没有请求映射状态和映射 URL 路径信息。为什么?

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

If you are trying to debug an application and you want to restore Spring Boot 2.0 style logging you should add the following to your 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