Spring Boot是一款基于Spring框架的快速web开发工具,但是我们在开发过程中需要知道当前使用的Spring Boot版本号,本文将从多个方面阐述如何查看Spring Boot的版本号。
一、查看POM文件
Spring Boot是基于Maven构建的,我们可以在项目的POM文件中查看Spring Boot的版本号。
1.8
2.4.5
从上述代码可以看出,项目当前使用的Spring Boot版本为2.4.5。
二、查看启动日志
在应用启动时,Spring Boot会打印出一些启动日志,其中包含了Spring Boot的版本号。
2021-07-27 14:00:13.881 INFO 3451 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-07-27 14:00:13.901 INFO 3451 --- [ restartedMain] com.example.demo.DemoApplication : Started DemoApplication in 2.317 seconds (JVM running for 2.658)
从上述代码可以看出,启动日志中包含的Spring Boot版本为2.4.5。
三、查看运行时依赖
我们可以通过Maven命令查看当前应用运行时所依赖的Spring Boot版本号。
mvn dependency:tree | grep spring-boot
从上述命令的输出结果可以查看当前运行时所依赖的Spring Boot版本。
四、查看Spring Boot Actuator
Spring Boot Actuator是Spring Boot的一个特性,可以提供应用的健康信息、性能指标、环境信息等。通过访问Spring Boot Actuator的/actuator/info端点,可以查看应用的详细信息,其中包含了Spring Boot的版本号。
http://localhost:8080/actuator/info
从上述代码可以看出,访问http://localhost:8080/actuator/info,可以查看当前应用的详细信息,其中包含了Spring Boot的版本。
五、总结
本文从多个方面阐述了如何查看Spring Boot的版本号,可以通过查看POM文件、启动日志、运行时依赖以及Spring Boot Actuator来查询当前应用的Spring Boot版本号。