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



当我在 eclipse 4.7.3 IDE 中运行我的 Spring 启动应用程序时,控制台不显示有关其余控制器的信息。尽管如此,当我使用浏览器测试它时,控制器仍在工作。

它只是一个"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:UsersAdmineclipse-workspace4.7.3aSprangHelloWorldSpringBoottargetclasses started by Admin in C:UsersAdmineclipse-workspace4.7.3aSprangHelloWorldSpringBoot)
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 路径信息。为什么?

日志输出在 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 中的更改(请参阅发行说明(

最新更新