len
len

Reputation: 404

Java: Eclipse console doesn't display Spring Controller information

When I run my spring boot application in eclipse 4.7.3 IDE, the console doesn't display the information about the rest controller. Nevertheless the controller is working when I test it with browser.

It is just a "Hello World" application:

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!";
    }
}

Output:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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)

As above it just display until "Started HelloWorldSpringBootApp in 1.904 seconds" without the request mapping status & mapped URL path info. Why?

Upvotes: 0

Views: 1933

Answers (1)

Misantorp
Misantorp

Reputation: 2821

The log output was changed in Spring 2.1. That changelog states that

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

This change however does not output what I would expect given this RestController

@RestController
public class HelloWorldController {

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

If I set the log level to trace it gives the expected output (though not in the exact same way as 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()

The requirement for trace log level is most likely due to a change in Spring Framework 5.1 (see release note)

Upvotes: 2

Related Questions