当我在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路径信息。为什么?
答案 0 :(得分: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)